Skip to content

@rjsf/core wrongly pulls the cjs module of nanoid #4726

@juliangilbey

Description

@juliangilbey

Prerequisites

What theme are you using?

core

Version

5.x

Current Behavior

I am trying to compile nbdime for Debian using webpack 5.97.1, but I get the following error when running webpack --mode=production on nbdime-webapp:

ERROR in node:crypto
Module build failed: UnhandledSchemeError: Reading from "node:crypto" 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.

(The full build and error message can currently be found at https://salsa.debian.org/jdg/nbdime/-/jobs/8044146)

My Debian colleague Jérémy Lal (@kapouer) has identified the source of the problem (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1111481). Paraphrasing what he has written there:

@rjsf/core builds esm/cjs bundles, and depends on nanoid.

nanoid correctly exports a browser bundle, but @rjsf/core doesn't use that file, it uses the cjs file, which requires node:crypto, which is not supported in the browser. The nanoid/index.browser.js file instead uses the native window.crypto.getRandomValues, and they are not interchangeable.

This produces bugs when a project makes a bundle using @rjsf/core, as (recent versions of) webpack give an error because the node: prefix is not supported. The problem isn't in webpack, it's really a problem with @rjsf/core not correctly exporting a browser bundle.

Expected Behavior

The webpacking of modules depending on @rjsf/core should complete without error.

Steps To Reproduce

Try compiling nbdime with a current version of webpack.

Environment

- OS: Debian GNU/Linux 13.0
- Node: 20.19.2
- npm: 9.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions