Next.js Discord

Discord Forum

Can't get Turbopack working because of failure to resolve local modules

Unanswered
Serengeti posted this in #help-forum
Open in Discord
Avatar
SerengetiOP
When I do next dev --turbopack and try to access the page, I get errors like this:
Module not found: Can't resolve '@packages/A'

Import map: aliased to relative "../path-to/moduleA" inside of [project]/


And this is caused by local modules I have that I have paths for in tsconfig.json. The paths are setup like this:
"paths": {
            "@packages/A": ["../path-to/moduleA"],
}


So it worked before --turbopack but now it doesn't Has anyone seen this and know how to address it? I am expecting not to get an error of course, and then I get the error.

40 Replies

Avatar
Sun bear
can you try this for once?

/** @type {import('next').NextConfig} */
const nextConfig = {
... /// your entire stuff here
  experimental: {
    turbo: {
      resolveAlias: {
        "@packages/A": "../path-to/moduleA"
      }
    }
  }
}

export default nextConfig
@Serengeti
Avatar
SerengetiOP
I was trying that, it didn't seem to make a difference. Let me see about it once more
Avatar
Sun bear
if this ain't working then we just resolve to local and

if nothing works, we can just disable turbopack
what version do you use?
Avatar
SerengetiOP
this is how I have it:
    experimental: {
        turbo: {
            resolveAlias: {
                "@packages/A": "../path-to/moduleA",
                                      }
                        }
        }
does it need to point to like an index.js file maybe?
The thing is I really want turbopack lol I am working on a UI project and it is going crazy slow so we are trying to speed it up
I have updated to nextjs 15.0.2
Avatar
Sun bear
/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    turbo: {
      resolveAlias: {
        "@packages/A": "../path-to/moduleA/index.ts", // or index.js
        // Or if you have a specific entry point:
        // "@packages/A": "../path-to/moduleA/src/main.ts",
        // or if you have multiple entry points ( I'm assuming you're using src as well )
        // "@packages/A/*": "../path-to/moduleA/src/*",  // uncommennt this if that's the case

      }
    }
  }
}

export default nextConfig


if this didn't work, try deleting cache and try again

hmu if that didn't work either
Avatar
SerengetiOP
okay thanks Vodka gonna give that a spin
Avatar
SerengetiOP
damnit still not working.
Avatar
Sun bear
fuck I missed a line here
Avatar
SerengetiOP
This is a monorepo with all of these packages being separate node modules. Interestingly I have so many packages, A, B, C, etc. Only one of the packages is not working.
what line?
Avatar
Sun bear
moduleDirectories: ['node_modules', '../path-to/moduleA']
Avatar
SerengetiOP
oh I see gracias
I assume you want this placed inside turbo object?
Avatar
Sun bear
yes
Avatar
SerengetiOP
I have this so far:

experimental: {
        turbo: {
            moduleDirectories: ['node_modules', '../path-to/moduleA'],
            resolveAlias: {
                "@packages/A": "../path-to/moduleA/lib/index.js",
            },
            rules: {
                '*.svg': {
                    loaders: ['@svgr/webpack'],
                    as: '*.js',
                },
            },
        },
    },


I tried setting the moduleDirectories piece to the specific file and also to just ../path-to/ but nothing has worked so far
Avatar
SerengetiOP
@Sun bear it's so sad. I am changing my tsconfig.json module and moduleResolution in desperation. Do you think that could help?
Avatar
Sun bear
I think that should automatically get updated if you have the right extensions
Avatar
SerengetiOP
tsconfig.json file should automatically get updated?
Avatar
Sun bear
I just got back from the drive
I'm still in car
If you have your extensions set up correctly
Yes
But actually you know what
In the include file do something like
** and select all ending with js /ts
Like example
"./src/**/*.js"

same for ts
Avatar
SerengetiOP
in tsconfig.json include?
Avatar
Sun bear
Yeah
Avatar
SerengetiOP
okay I will try that shit and pray and let you know
Avatar
Sun bear
I fixed the thing
Earlier it got used like a bold thing
Avatar
SerengetiOP
a code sample you provided?
Avatar
Sun bear
Yeah
Avatar
SerengetiOP
this code sample?
Avatar
SerengetiOP
thanks again man you have been extremely helpful.

Is this supposed to help turbopack/next identify the external packages that it can't seem to detect?

Actually, here is the include that is already in there:

"include": [
        "next-env.d.ts",
        "./src/**/*.ts",
        "*/**/*.ts",
        "**/*.tsx",
        "**/*.js",
        "@types",
        ".next/types/**/*.ts"
    ]


But I changed it to include my package to see if that helped:

"include": [
        "next-env.d.ts",
        "./src/**/*.ts",
        "*/**/*.ts",
        "**/*.tsx",
        "**/*.js",
        "@types",
        ".next/types/**/*.ts",
        "../moduleA/**/*.ts", // this is the correct path
                "../moduleA/**/*.tsx"
    ]
Avatar
SerengetiOP
Avatar
Sun bear
Neat !
I'll go read it later.