-
Notifications
You must be signed in to change notification settings - Fork 27.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnhandledSchemeError
when dependency uses node:assert
imports
#28774
Comments
Any updates on this issue? Facing the same problem but for |
Is the
This is true throughout the micromark ecosystem as far as I know, so support for this would be great! Edit: mentioned in remarkjs/react-markdown#641, micromark/micromark#87, and remarkjs/react-markdown#632 |
I'm still getting this error with next.js 12 |
Me too, using remark getting this error |
Still getting this error
|
Looks like |
Here's a minimal reproduction repo with no other dependencies besides Next.js and React themselves, if that's helpful. https://github.com/manovotny/nextjs-node-protocol-bug |
This comment was marked as off-topic.
This comment was marked as off-topic.
Also seeing this issue when using MSW with NextJS |
Next.js adds fallbacks for node built-in modules by using next.js/packages/next/build/webpack-config.ts Lines 628 to 659 in 384953b
And this feature now doesn't support node protocol: webpack/webpack#14166 |
Not sure if this fix for a similar bug is helpful: webpack/webpack#15577 |
@OskarGroth this went out in webpack 5.71.0, Next.js is using webpack 5.72.0 on the latest stable (12.1.5). |
I can confirm, that issue is still there in version 12.1.5. |
@timneutkens I'm using Next.js 12.1.5 and still experiencing this issue. More info about the error I'm getting and the troubleshooting I've done: leafac/rehype-shiki#7 |
No longer experiencing this issue (12.1.5). |
I am facing the same issue, after updating to Next 12.1.5
|
I'm no longer able to reproduce the OP's issue. If you still do, please open a new issue with an attached reproduction, making sure you have tested the Remember to check which Node.js versions support |
i am still seeing the exact same error message with
|
Oh, interesting. The reproduction uses It might be because the client-side code elimination tool isn't able to recognize the module you are using is for server-only. import fs from "node:fs"
export default function Home() {
return null
}
export async function getStaticProps() {
console.log(fs)
return { props: {} }
} This works as the code can be analyzed and Next.js will know where the Let's reopen and investigate further. |
Any progress on this? Got hit by this error too while trying to migrate the project to ESM. EDIT: I guess a separately installed |
This is related to webpack/webpack#13290 (fresh Next.js comments at the bottom of the thread) For those looking for a workaround, I wrote a Webpack configuration handler in TypeScript. You can simply use it by setting your import Webpack from 'webpack'
import type { WebpackConfigContext } from 'next/dist/server/config-shared'
/**
* Next.js did not define any types for its Webpack configs.
*
* @see https://github.com/vercel/next.js/blob/canary/packages/next/compiled/webpack/webpack.d.ts
* @see https://github.com/vercel/next.js/blob/60c8e5c29e4da99ac1aa458b1ba3bdf829111115/packages/next/server/config-shared.ts#L67
*/
export interface WebpackContext extends WebpackConfigContext {
webpack: typeof Webpack
}
/**
* Handles the Webpack configuration.
*
* @param config - The Webpack configuration options.
* @param context - The Webpack context
*
* @returns A Webpack configuration object.
*/
function webpackConfigurationHandler(
config: Webpack.Configuration,
context: WebpackContext
): Webpack.Configuration {
/**
* Add support for the `node:` scheme available since Node.js 16.
*
* @see https://github.com/vercel/next.js/issues/28774
*/
config.plugins = config.plugins ?? []
config.plugins.push(
new context.webpack.NormalModuleReplacementPlugin(/^node:/, (resource: { request: string }) => {
resource.request = resource.request.replace(/^node:/, '')
})
)
return config
} |
@nbouvrette Thanks for the fix. After that everything works fine, but we get a warning from typescript after adding the plugin.
Not sure if this is problematic though. |
Slight modification I made so I could use the new format using
|
[fix] some UI detail bugs [fix] webpack building bug (vercel/next.js#28774)
[fix] some UI detail bugs [fix] webpack building bug (vercel/next.js#28774)
This is a great workaround! |
Sill seeing this in next@13.3.1 |
|
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 (#34263 (comment)) which is pretty limiting not being able to do this 😬 |
Hi everyone, this should be fixed in newer versions of Next.js, make sure you upgrade ( If you still see an issue and you think it's related, please open a new one with an attached reproduction, thanks! 💚 |
@balazsorban44 which version should have the fix exactly? I can't find any mention in the release notes of the 2 latest version ( I tried updating to - error node:path
Module build failed: UnhandledSchemeError: Reading from "node:path" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
Import trace for requested module:
node:path
../lib/index.js |
@nbouvrette It was fixed many releases ago. Keep in mind that |
@timneutkens for the explanation - I think I understand what is going on here. The error I am getting is on The reason why it works with my workaround is because the Webpack has shims for some Node.js core modules that provide equivalent functionality in the browser, and Ideally I would hope that this would work our of the box without having me using special Webpack config. What do you think @timneutkens @balazsorban44 ? Or should I open another issue for this use case? |
We eventually want to remove these default shims because they increase bundle size massively in most cases. |
Ok I get your point @timneutkens - I suspect for my specific use case the shims are pretty small but I could always try to replace them without having to rely on Webpack so that if you ever decide to drop the default shims my code still work. |
Definitely yeah 👍 |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
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 runningyarn 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.git
cd issue-next-webpack-node-imports
yarn && yarn add next@latest && yarn dev
The text was updated successfully, but these errors were encountered: