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

This require call is not allowed because the transitive dependency "node-modules-polyfills:node:worker_threads" contains a top-level await #282

Open
ffMathy opened this issue Sep 30, 2024 · 2 comments

Comments

@ffMathy
Copy link

ffMathy commented Sep 30, 2024

Issue description

✘ [ERROR] This require call is not allowed because the transitive dependency "node-modules-polyfills:node:worker_threads" contains a top-level await

    node_modules/undici/lib/web/websocket/events.js:6:32:
      6 │ const { MessagePort } = require('node:worker_threads')
        ╵                                 ~~~~~~~~~~~~~~~~~~~~~

  The file "node-modules-polyfills-commonjs:node:worker_threads" imports the file
  "node-modules-polyfills:node:worker_threads" here:

    node-modules-polyfills-commonjs:node:worker_threads:1:14:
      1 │ export * from 'node:worker_threads'
        ╵               ~~~~~~~~~~~~~~~~~~~~~

  The top-level await in "node-modules-polyfills:node:worker_threads" is here:

    node-modules-polyfills:node:worker_threads:97:49:
      97 │   ([{ threadId, workerData, environmentData }] = await once(parentPort, 'message'));
         ╵                                                  ~~~~~


 NX   Build failed with 1 error:

node_modules/undici/lib/web/websocket/events.js:6:32: ERROR: This require call is not allowed because the transitive dependency "node-modules-polyfills:node:worker_threads" contains a top-level await
Error: Build failed with 1 error:
node_modules/undici/lib/web/websocket/events.js:6:32: ERROR: This require call is not allowed because the transitive dependency "node-modules-polyfills:node:worker_threads" contains a top-level await
    at failureErrorWithLog (/workspaces/WATS/node_modules/esbuild/lib/main.js:1476:15)
    at /workspaces/WATS/node_modules/esbuild/lib/main.js:945:25
    at /workspaces/WATS/node_modules/esbuild/lib/main.js:1354:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Code sample

Code is under NDA, and I tried spending hours creating a repro with no luck.

Package version

1.6.7

Node.js version

v20.17.0

Operating system

No response

I have tested this issue on a next release

No response

@Benjythebee
Copy link

Benjythebee commented Feb 14, 2025

Same issue in a simple

import esbuildPluginTsc from 'esbuild-plugin-tsc';
import { dtsPlugin } from "esbuild-plugin-d.ts";
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
export function createBuildSettings(options) {
  return {
    entryPoints: ['src/index.ts'],
    outfile: 'dist/index.js',
    platform: 'node',
    // inject: ['cjs-shim.ts'],
    bundle: true,
    target:'node18',
    format: 'esm',
    external:["natural"],
    plugins: [
      // esbuildPluginTsc({
      //   force: true
      // }),
      nodeModulesPolyfillPlugin(),
      dtsPlugin(),
    ],
    ...options
  }
}

Issue also present in 1.6.5,1.6.2

@imranbarbhuiya
Copy link
Owner

@Benjythebee can you provide me a minimal code sample that throws this error with your config?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants