Build dependencies failed at import and can't resolve 'path'
See original GitHub issueI’m new here. Thanks for this awesome project! So, currently I’m getting this issue, I’m invested time to solve, but without success. Any help is welcome.
[webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Parsing of /node_modules/@contentlayer/core/dist/getConfig/index.js for build dependencies failed at 'import(`file://${modulePath}?x=${new Date()}`)'.
Build dependencies behind this expression are ignored and might cause incorrect cache invalidation.
[webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Can't resolve 'path' in '/node_modules/@contentlayer/core/dist'
while resolving 'path' in /node_modules/@contentlayer/core/dist as file
at resolve esm file path
at file dependencies /node_modules/@contentlayer/core/dist/mdx.js
at file /node_modules/@contentlayer/core/dist/mdx.js
at resolve esm file ./mdx.js
at file dependencies /node_modules/@contentlayer/core/dist/index.js
at file /node_modules/@contentlayer/core/dist/index.js
at resolve esm file @contentlayer/core
at file dependencies /node_modules/next-contentlayer/dist/plugin.js
at file /node_modules/next-contentlayer/dist/plugin.js
at resolve esm file ./plugin.js
at file dependencies /node_modules/next-contentlayer/dist/index.js
at file /node_modules/next-contentlayer/dist/index.js
at resolve esm file next-contentlayer
at file dependencies /apps/web/next.config.mjs
at file /apps/web/next.config.mjs
at resolve commonjs /apps/web/next.config.mjs
[webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Can't resolve 'path' in '/node_modules/@contentlayer/core/dist'
while resolving 'path' in /node_modules/@contentlayer/core/dist as file
at resolve esm file path
at file dependencies /node_modules/@contentlayer/core/dist/mdx.js
at file /node_modules/@contentlayer/core/dist/mdx.js
at resolve esm file ./mdx.js
at file dependencies /node_modules/@contentlayer/core/dist/index.js
at file /node_modules/@contentlayer/core/dist/index.js
at resolve esm file @contentlayer/core
at file dependencies /node_modules/next-contentlayer/dist/plugin.js
at file /node_modules/next-contentlayer/dist/plugin.js
at resolve esm file ./plugin.js
at file dependencies /node_modules/next-contentlayer/dist/index.js
at file /node_modules/next-contentlayer/dist/index.js
at resolve esm file next-contentlayer
at file dependencies /apps/web/next.config.mjs
at file /apps/web/next.config.mjs
at resolve commonjs /apps/web/next.config.mjs
Package versions:
- contentlayer: v0.1.1
- next: v12.1.0
- next-contentlayer: v0.1.1
- react: v17.0.2
- typescript: v4.5.5
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (2 by maintainers)
Top Results From Across the Web
Error: Can't resolve 'path' in 'C:\work\demo\node_modules ...
The path dependency is part of the Node.js runtime.The alternative is to just use the mime module. This module was made to fix...
Read more >CommonJS modules | Node.js v19.3.0 Documentation
Local modules and JSON files can be imported using a relative path (e.g. ./ , ./foo , ./bar/baz , ../foo ) that will...
Read more >Have a JavaScript Module Not Found Error ... - Airbrake Blog
If you're seeing a "module not found: error: can't resolve," in your Javascript code, here's an explanation as to why and how to...
Read more >Module Resolution - webpack
A resolver is a library which helps in locating a module by its absolute path. A module can be required as a dependency...
Read more >Common TypeScript module problems and how to solve them
Problem 1: Irregular location of dependencies ; node_modules in the ; src directory even though ; node_modules is located outside the ; src ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve taken a deeper look into this issue and the provided repro (thanks @mshick). Here is what I’ve found:
It seems like the original issue was related to the usage of the Next.js plugin and was by @brunowego by using
export default withContentlayer()(nextConfig)
in the Next config.To avoid other users potentially running into this problem I’m planning to introduce this API change for the Next.js plugin: https://github.com/contentlayerdev/contentlayer/issues/140 (Feedback wanted!)
Additionally to the original problem (see (1)) there seems to be another problem (which technically is only a “warning”) which isn’t a problem in Contentlayer itself but rather a bug in Next.js / Webpack (see https://github.com/vercel/next.js/issues/33693) when using
next.config.mjs
instead ofnext.config.js
. My understanding is that this issue will be addressed by the Next.js team very soon.If you don’t want to wait until this problem is addressed in Next.js, please use
next.config.js
(via CommonJS) for now.Given (1) was successfully solved and (2) is an external problem with known workaround, I’ll close this issue. If there are any further problems related to this, please provide further context in the comments or on Discord.
Same issue here. The problem occurs when using a
next.config.mjs
file. When I switch to an identicalnext.config.js
there is no problem.Reproduction here: https://github.com/mshick/newnewsite