contentlayer: Build dependencies failed at import and can't resolve 'path'
I’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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 22 (2 by maintainers)
Commits related to this issue
- Fix. contentslayer build error fix https://github.com/contentlayerdev/contentlayer/issues/129 해당 이슈 참고하여 수정 — committed to Seo0H/seo0h.github.io by Seo0H 9 months ago
Example
next.config.js, for the next person who comes along and sees this:So since ContentLayer doesn’t work correctly with ESM/next.config.mjs, that means it’s incompatible with the plaiceholder package, which requires ESM/next.config.mjs.
Shame. I hope this is resolved at some point.
Still getting this error.
This is my MDX:
My next config is already wrapped with
withContentlayer.What could be off?
Same issue here. The problem occurs when using a
next.config.mjsfile. When I switch to an identicalnext.config.jsthere is no problem.Reproduction here: https://github.com/mshick/newnewsite
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.mjsinstead 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.
@schickling appears this was closed without resolution
I’ll take a more in-depth look next week when I’m working on Contentlayer again but in the meanwhile you can try to change this line https://github.com/brunowego/issue-reproduction/blob/next-contentlayer-129/next.config.mjs#L10 to
I also having the same issue here like saying -
webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Parsing of /home/kinfish/loglib/node_modules/.pnpm/@contentlayer+core@0.3.1_esbuild@0.17.0/node_modules/@contentlayer/core/dist/dynamic-build.js for build dependencies failed at 'import(file://${compiledConfigPath}`same error,how to fix it?