#Turborepo - trying to import from package to another doens't work
1 messages · Page 1 of 1 (latest)
Based on the knowledge sources provided, I can see that you're experiencing an issue with importing between packages in a Turborepo monorepo when using Next.js with Turbopack. This is a common issue that several users have reported.
The error you're seeing suggests there's a problem with how your packages are being resolved. From the knowledge sources, there are a few potential causes and solutions:
-
Path resolution in Turbopack: Turbopack has stricter filesystem access than webpack by default, which can cause issues with imports between packages in a monorepo as mentioned here.
-
Package configuration: The error message indicates an invalid module specifier "@config" instead of "@repo/config" which suggests there might be a mismatch in how you've configured your package names.
Here are some potential solutions:
-
Check your package.json configuration: Make sure your package names in package.json match what you're importing. For example, if you're importing
@repo/config, the package name in the config package's package.json should be@repo/config. -
Try using resolveAlias in next.config.js: As mentioned in this issue, you can add a configuration to help Turbopack resolve your internal packages:
const nextConfig = {
experimental: {
turbo: {
resolveAlias: {
'@repo/config': '../packages/config',
},
},
},
};
export default nextConfig;
- Set the root directory for Turbopack: As a workaround mentioned in the same issue, you can set the root directory to help Turbopack find your packages:
const nextConfig = {
experimental: {
turbo: {
root: '..',
},
},
};
export default nextConfig;
- Check for lockfiles: Turbopack automatically detects the root by looking for a lockfile. If you have multiple lockfiles in your project, it might cause confusion. Make sure you only have one lockfile at the root of your monorepo.
If you're still experiencing issues, you might want to try running without the --turbo flag temporarily to see if that resolves the issue, as several users reported that their imports worked correctly without Turbopack.
Kapa.ai
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@silk mica Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@supple heath I'm using TURBOREPO, the monorepo from nextjs
Let me check the knowledge base for you again. Give me one moment! :books:
I understand you're using Turborepo, which is a monorepo tool developed by Vercel (the same company behind Next.js). However, I should clarify that Turborepo itself is distinct from Next.js, though they're often used together.
Based on your previous question about importing between packages in your monorepo, it seems you're experiencing module resolution issues. This is a common challenge in monorepos, especially when using ESM imports.
From the knowledge sources, several users have reported similar issues with package imports in Turborepo setups. Here are some potential solutions:
-
Check package naming consistency: Ensure your package names in each package.json match exactly what you're importing. For example, if importing
@repo/config, the package should be named exactly that in its package.json. -
Package exports configuration: Make sure your packages properly define their exports in package.json. Some issues arise when packages don't correctly specify what they export as mentioned in this issue.
-
For pnpm users: If you're using pnpm, you might need to add hoisting patterns for certain packages:
public-hoist-pattern[]=*package-name*
- Check for multiple lockfiles: Having multiple lockfiles in your project can confuse module resolution. Make sure you only have one lockfile at the root of your monorepo.
If you're specifically using Next.js with Turbopack in your monorepo, you might need additional configuration in your next.config.js file, but that would only apply to the Next.js applications within your monorepo.