Skip to content
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

Cannot load module: 'util' even though it is polyfilled #866

Open
Strydom opened this issue Oct 30, 2024 · 0 comments
Open

Cannot load module: 'util' even though it is polyfilled #866

Strydom opened this issue Oct 30, 2024 · 0 comments

Comments

@Strydom
Copy link

Strydom commented Oct 30, 2024

When bundling a react component using esbuild and trying to execute it within the JS context, it is unable to require the util package even though it is provided.

private val context: Context = Context
    .newBuilder("js")
    .allowAllAccess(true)
    .allowHostAccess(HostAccess.ALL)
    .allowIO(IOAccess.ALL)
    .option("js.commonjs-require", "true")
    .option("js.commonjs-require-cwd", "path/to/node_modules")
    .option("js.commonjs-core-modules-replacements", "stream:stream-browserify")
    .build()

This throws an error

context.eval(serverScript)

But this does not

context.eval("js", """
    const process = { env: { NODE_DEBUG: false } }
    const util = require('util')
""".trimIndent())

The part of the serverScript throwing the error TypeError: Cannot load module: 'util'

// node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom-server.node.development.js
var require_react_dom_server_node_development = __commonJS({
  "node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom-server.node.development.js"(exports2) {
    "use strict";
    init_process();
    if (process.env.NODE_ENV !== "production") {
      (function() {
        "use strict";
        var React3 = require_react();
        var util = require("util");

esbuild

await build({
    entryPoints: [
        'components/**/Server*'
    ],
    bundle: true,
    outdir: '../src/main/resources/components/server',
    platform: "node",
    format: "cjs",
    inject: [
        './process.js'
    ]
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant