contentlayer: Error when building with contentlayer 0.3.4 and Next.js 13 App Router
When I run pnpm contentlayer build, I run into an error within node_modules and cannot resolve it.
Versions
"contentlayer": "^0.3.4",
"next": "13.4.9",
Error Message
import { ConsoleSpanExporter, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";
^^^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'ConsoleSpanExporter' not found. The requested module '@opentelemetry/sdk-trace-base' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from '@opentelemetry/sdk-trace-base';
const { ConsoleSpanExporter, SimpleSpanProcessor } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 46
- Comments: 81 (4 by maintainers)
Commits related to this issue
- added fix from github vercel build error https://github.com/contentlayerdev/contentlayer/issues/506#issuecomment-1625210487 — committed to JosephJL/joseph-portfolio by JosephJL a year ago
- Downgrade contentlayer to 0.3.1 I ran into the same error as https://github.com/contentlayerdev/contentlayer/issues/506#issue-1792860737 — committed to rjmccluskey/richmccluskey.dev by rjmccluskey a year ago
- Override bad deps as workaround for contentlayer issues See https://github.com/contentlayerdev/contentlayer/issues/506#issuecomment-1625210487 — committed to rjmccluskey/richmccluskey.dev by rjmccluskey a year ago
- web: override opentelemetry dependency versions using pnpm See https://github.com/contentlayerdev/contentlayer/issues/506\#issuecomment-1625210487 — committed to profclems/compozify by profclems a year ago
- got through dependency hell had to downgrade 0.3.4 to 0.3.1 of content-layer and next-contentlayer. Had to npm override opentelemtry see https://github.com/contentlayerdev/contentlayer/issues/506. st... — committed to Fredenck/fredsite by Fredenck a year ago
- Update Next and ContentLayer To get the new version of Next with ContentLayer working, i had to override a few versions. Please check out the issue at https://github.com/contentlayerdev/contentlayer/... — committed to sdorra/sdorra.dev by sdorra a year ago
- update opentelemetry dependency to fix cjs error (#6091) ## Summary Per https://github.com/contentlayerdev/contentlayer/issues/506 https://github.com/open-telemetry/opentelemetry-js/releases/ta... — committed to highlight/highlight by Vadman97 a year ago
Confirmed. I fixed it by overriding dependency versions (using pnpm).
Ran into this as well, looking forward to the fix. Thank folks!
For the
next/imageerror, the workaround suggested here fixed it for me.Same issue, can confirm it
This is the equivalent version for
yarn:Remember to run
yarn install --force.Still facing this same issue with Turbo, pnpm, and Next.js 13.5.4. Been months
Downgrading to version
^0.3.1seemed to work. I’m able to runpnpm contentlayer buildbut the newest version (0.3.4) of contentlayer does not work for me.Hate to be that guy - but I would love to hear if a fix is in the pipeline as I see no comms from the maintainers.
I’ve just tested locally with
nextversion13.4.19and I don’t have this problem anymore. Hopefully it’s solved now 🙏@sakibul-islam
Similar solution worked for me (using npm)
The following can be used inside package.json
I also rolled back contentlayer to
v0.3.2and next tov13.4.8and next-contentlayer tov0.3.1rm -r node_modulesthennpm iand it was working…That’s likely a bug caused by Contentlayer itself. It doesn’t work well for App Router, try
(props) => <Image {...props} />.You can open another issue instead.
Not to rush anybody but there’s a bunch of people in the issues, discussions, and PRs who would be happy to help. Is there any chance the Maintainers can take a look at/accept some of the help?
Now that https://github.com/open-telemetry/opentelemetry-js/pull/4016 is merged, it’ll be fixed soon ig.
EDIT: Should be fine now, finally.
Node v18.15.0 and Ubuntu 20.04.6 LTS. I’ve tested on Node v20.3.0, and it works fine too. I guess I should mention: there is another issue with recent versions of Next.js that makes contentlayer not to be executed automatically. So I also had to tweak the scripts in the
package.json:With these, things work as expected.
I tried switching from npm to pnpm in my personal project, but I’m still encountering the
next/imageerror even with the latest Contentlayer and NextJS 13 versions. However, it’s still working fine when I usenpm.I’m hoping that this issue will be fixed soon 🙏
I made it work with the resolution as well, but the issue arises because I’m using a monorepo. I need to add the resolution in the root package.json, not inside the package folder package.json. It needs to be located next to the lock file thanks for everybody 🥇
@seththeskier @ThiagoUnder @luxonauta, have you tried downgrading the version number of contentlayer?
For now, reverting to an earlier patch may work for you. As long as you don’t need 0.3.4, I’ve been running
0.3.1in a recent project without problems.In a different reply, @mauriciomutte said they could run
0.3.2as well without problems.Best of luck!
@brianschnee it is not related to the App router, but rather to ESM; don’t know what contentlayer has changed but the package stopped building properly when using
.mjs/ESM. Using0.3.1works for me as well.Exactly the latest versions of both of them, next 13.4.19 and contentlayer 0.3.4. Not sure it’s working for everyone, but at least I got it working in CodeSandbox
The latest version, 0.3.4 works for me
Been researching this for an hour or so (maybe I’m bad at Googling), this is the first workaround I’ve found that’s worked for me.
I haven’t been able to grasp it fully, but could you please modifying the next.config.mjs file to utilize CommonJS instead of ECMAScript Modules (ESM) and convert the file extensions from .mjs to .js?
I’m running into this as well when trying the pnpm overriding solution. Does anyone have a solution?
I’ve tried adding
to package.json but now I have the following error running dev server:
@emptypockets-dev I’m using
contentlayer: 0.3.1andnext-contentlayer: 0.3.1for the time being. @mauriciomutte mentioned that0.3.2works for them as well.The same for me… using
0.3.2works as well but upgrading to0.3.4shows the error mentioned