next.js: `UnhandledSchemeError` when dependency uses `node:assert` imports
What version of Next.js are you using?
11.1.2
What version of Node.js are you using?
14.17.6
What browser are you using?
ff
What operating system are you using?
linux
How are you deploying your application?
vercel
Describe the Bug
In a project which has micromark-util-events-to-acorn@1.0.1 as a dependency, i get the following error when running yarn dev:
Module build failed: UnhandledSchemeError: Reading from "node:assert" is not handled by plugins (Unhandled scheme).

Things to note about this package: it uses an export map with a “development” user condition, and node:assert is only used there, not in the exported production build.
Expected Behavior
No error.
To Reproduce
git clone https://github.com/stefanprobst/issue-next-webpack-node-imports.gitcd issue-next-webpack-node-importsyarn && yarn add next@latest && yarn dev- open http://localhost:3000/
- See error message
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 23
- Comments: 36 (19 by maintainers)
Commits related to this issue
- [add] Project list of Home page based on Group API & model [fix] some UI detail bugs [fix] webpack building bug (vercel/next.js#28774) — committed to kaiyuanshe/kaiyuanshe.github.io by TechQuery 2 years ago
- [add] Project list of Home page based on Group API & model [fix] some UI detail bugs [fix] webpack building bug (vercel/next.js#28774) — committed to kaiyuanshe/kaiyuanshe.github.io by TechQuery 2 years ago
- (migration) resolve the error 'UnhandledSchemeError' for node: prefix for Webpack 5 (resources) - https://github.com/vercel/next.js/issues/28774 - https://webpack.js.org/plugins/normal-module-replacem... — committed to AlexsLemonade/refinebio-web by nozomione a year ago
Oh, interesting. The reproduction uses
11.1.2, but upgrading tolatestdoes throw the error after all. 👀It might be because the client-side code elimination tool isn’t able to recognize the module you are using is for server-only.
This works as the code can be analyzed and Next.js will know where the
node:import is being used.Let’s reopen and investigate further.
I’m still getting this error with next.js 12
Any updates on this issue? Facing the same problem but for
xdm.Slight modification I made so I could use the new format using
next@12.3.0andwebpack@5.74.0, if this is helpful:Sill seeing this in next@13.3.1
@sebald I recall briefly seeing this error and I think I fixed it by deleting the
.nextdirectory. If this doesn’t work, you can check my full implementation here and maybe spot something I am missing. I don’t have this error on my end with this implementation.i am still seeing the exact same error message with
next@12.1.6andnode@16.14.2:Not sure if this fix for a similar bug is helpful: https://github.com/webpack/webpack/pull/15577 Can NextJS make sure to update their Webpack module to this version and see if it resolves this?
Next.js adds fallbacks for node built-in modules by using
resolve.fallback:https://github.com/vercel/next.js/blob/384953b35c5e9935bb4a2fcdfe5056efb73cd740/packages/next/build/webpack-config.ts#L628-L659
And this feature now doesn’t support node protocol: https://github.com/webpack/webpack/issues/14166
⚠️ This does not apply to middleware ⚠️
If you see compile errors related to node modules or
node:prefix, that is because in Next 13 middleware ALWAYS runs in Edge runtime without a way to opt-out.This means that whatever you import in
middleware.ts, and their dependencies, must not import node packages or use edge-incompatible APIsconfig.experimental.runtimeorexport const runtime = "nodejs"and they will be ignored.streamorcrypto)next@13.3.1Example failures
Even after closing https://github.com/webpack/webpack/issues/13290 and supposed fix in https://github.com/vercel/next.js/pull/45149 merged in Jan, it’s still failing for code in my
middleware.tsthat imports a 3rd party module, which seems to have@aws-sdktransient dependency, which dynamically importsnode:fileWe eventually want to remove these default shims because they increase bundle size massively in most cases.
node:is meant to signal “In the Node.js environment” so hence why we intentionally do not add shims for those.Hi everyone, this should be fixed in newer versions of Next.js, make sure you upgrade (
npm i next@latest)! I tested the reproduction on top of this issue and it worked.If you still see an issue and you think it’s related, please open a new one with an attached reproduction, thanks! 💚
wow thanks a lot for clarifying this @Thinkscape always felt there’s something off with middleware as I couldn’t get mysql2 working which I use in dev locally and was always confused but now that not even cuid2 works got me finally investigating.
This is actually reeaally annoying as so far, I think, middleware is the only place to set cookies on a request without user interaction or calling an api, which is already pretty annoying but have this middleware limited like this 🥲
Also I’d really like to be able to pass data from middleware to server components/actions and routes (https://github.com/vercel/next.js/discussions/34263#discussioncomment-5821645) which is pretty limiting not being able to do this 😬
This is a great workaround!
Is the
node:protocol supported in the current Next.js webpack configuration?This is true throughout the micromark ecosystem as far as I know, so support for this would be great!
Edit: mentioned in https://github.com/remarkjs/react-markdown/issues/641, https://github.com/micromark/micromark/issues/87, and https://github.com/remarkjs/react-markdown/issues/632