This require call is not allowed because the transitive dependency "node-modules-polyfills:node:worker_threads" contains a top-level await
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
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 can you provide me a minimal code sample that throws this error with your config?
same issue here
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 can you create a minimal repro where I can test it?
same problem here :/
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?
Anyone who's experiencing this issue, please provide me a code sample which reproduces this issue and where I can test the error
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.
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