esbuild-plugins-node-modules-polyfill icon indicating copy to clipboard operation
esbuild-plugins-node-modules-polyfill copied to clipboard

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

Open ffMathy opened this issue 1 year ago • 10 comments

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

ffMathy avatar Sep 30 '24 09:09 ffMathy

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

Benjythebee avatar Feb 14 '25 21:02 Benjythebee

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

imranbarbhuiya avatar Feb 15 '25 19:02 imranbarbhuiya

same issue here

himself65 avatar May 14 '25 00:05 himself65

import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { build } from 'esbuild';

build({
  entryPoints: ['src/main.ts'],
  outdir: 'dist',
  bundle: true,
  target: 'node22',
  format: 'esm',
  platform: 'node',
  plugins: [nodeModulesPolyfillPlugin()],
});

himself65 avatar May 14 '25 00:05 himself65

@himself65 can you create a minimal repro where I can test it?

imranbarbhuiya avatar May 16 '25 06:05 imranbarbhuiya

same problem here :/

BowgartField avatar Jun 04 '25 09:06 BowgartField

I guess just a simple TLA script? I already forget what it is

@himself65 can you create a minimal repro where I can test it?

himself65 avatar Jun 04 '25 12:06 himself65

Anyone who's experiencing this issue, please provide me a code sample which reproduces this issue and where I can test the error

imranbarbhuiya avatar Jun 04 '25 14:06 imranbarbhuiya

Anyone who's experiencing this issue, please provide me a code sample which reproduces this issue and where I can test the error

I'm working on creating a reproduction repo.

BowgartField avatar Jun 05 '25 13:06 BowgartField

Encountered same issue, but on massive monorepo project and and it happens only on one of the packages, i cant pinpoint what causes it to provide reproduction

Dima-Kal avatar Aug 26 '25 09:08 Dima-Kal