Can't get Turbopack working because of failure to resolve local modules
Unanswered
Serengeti posted this in #help-forum
SerengetiOP
When I do next dev --turbopack and try to access the page, I get errors like this:
And this is caused by local modules I have that I have paths for in tsconfig.json. The paths are setup like this:
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.
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
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
SerengetiOP
I was trying that, it didn't seem to make a difference. Let me see about it once more
Sun bear
if this ain't working then we just resolve to local and
if nothing works, we can just disable turbopack
if nothing works, we can just disable turbopack
what version do you use?
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
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
SerengetiOP
okay thanks Vodka gonna give that a spin
SerengetiOP
damnit still not working.
Sun bear
fuck I missed a line here
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?
Sun bear
moduleDirectories: ['node_modules', '../path-to/moduleA']
SerengetiOP
oh I see gracias
I assume you want this placed inside turbo object?
Sun bear
yes
SerengetiOP
I have this so far:
I tried setting the moduleDirectories piece to the specific file and also to just ../path-to/ but nothing has worked 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
SerengetiOP
@Sun bear it's so sad. I am changing my tsconfig.json module and moduleResolution in desperation. Do you think that could help?
Sun bear
I think that should automatically get updated if you have the right extensions
SerengetiOP
tsconfig.json file should automatically get updated?
Sun bear
I just got back from the drive
I'm still in car
I'm still in car
If you have your extensions set up correctly
Yes
Yes
But actually you know what
In the include file do something like
** and select all ending with js /ts
Like example
same for ts
"./src/**/*.js"
same for ts
SerengetiOP
in tsconfig.json include?
Sun bear
Yeah
SerengetiOP
okay I will try that shit and pray and let you know
Sun bear
I fixed the thing
Earlier it got used like a bold thing
Earlier it got used like a bold thing
SerengetiOP
a code sample you provided?
Sun bear
Yeah
SerengetiOP
this code sample?
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:
But I changed it to include my package to see if that helped:
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"
]
SerengetiOP
this fixed it bro: https://github.com/vercel/next.js/issues/71886
Sun bear
Neat !
I'll go read it later.