diff --git a/benchmark/fixtures/echo.worker.js b/benchmark/fixtures/echo.worker.js index 167a28ad23e830..e8512650edb02e 100644 --- a/benchmark/fixtures/echo.worker.js +++ b/benchmark/fixtures/echo.worker.js @@ -1,6 +1,6 @@ 'use strict'; -const { parentPort } = require('worker_threads'); +const { parentPort } = require('@nodejs/worker_threads'); parentPort.on('message', (msg) => { parentPort.postMessage(msg); diff --git a/benchmark/fixtures/require-cachable.js b/benchmark/fixtures/require-cachable.js index f651728dc78f35..690ec1a49c7fd9 100644 --- a/benchmark/fixtures/require-cachable.js +++ b/benchmark/fixtures/require-cachable.js @@ -3,7 +3,7 @@ const list = require('internal/bootstrap/cache'); const { isMainThread -} = require('worker_threads'); +} = require('@nodejs/worker_threads'); for (const key of list.cachableBuiltins) { if (!isMainThread && key === 'trace_events') { diff --git a/benchmark/misc/startup.js b/benchmark/misc/startup.js index 1350cd291e2b18..8bad10756716a0 100644 --- a/benchmark/misc/startup.js +++ b/benchmark/misc/startup.js @@ -66,7 +66,7 @@ function main({ dur, script, mode }) { script = path.resolve(__dirname, '../../', `${script}.js`); if (mode === 'worker') { - Worker = require('worker_threads').Worker; + Worker = require('@nodejs/worker_threads').Worker; bench.start(); start(state, script, bench, spawnWorker); } else { diff --git a/benchmark/worker/echo.js b/benchmark/worker/echo.js index 32c4bddf7d5f77..bc745b07b6790c 100644 --- a/benchmark/worker/echo.js +++ b/benchmark/worker/echo.js @@ -12,7 +12,7 @@ const bench = common.createBenchmark(main, { const workerPath = path.resolve(__dirname, '..', 'fixtures', 'echo.worker.js'); function main(conf) { - const { Worker } = require('worker_threads'); + const { Worker } = require('@nodejs/worker_threads'); const n = +conf.n; const workers = +conf.workers; diff --git a/doc/api/errors.md b/doc/api/errors.md index f0c118fd59d5e9..87b28a5dd663fd 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1234,6 +1234,12 @@ An invalid HTTP token was supplied. An IP address is not valid. + +### ERR_INVALID_NODE_BUILTIN + +An attempt was made to load a module from the Node.js namespace that doesn't +exist. Only built in modules can be require from '@nodejs/'. + ### ERR_INVALID_OPT_VALUE diff --git a/doc/api/worker_threads.md b/doc/api/worker_threads.md index ca3aed6140ca16..3c3f558efcd482 100644 --- a/doc/api/worker_threads.md +++ b/doc/api/worker_threads.md @@ -9,7 +9,7 @@ on independent threads, and to create message channels between them. It can be accessed using the `--experimental-worker` flag and: ```js -const worker = require('worker_threads'); +const worker = require('@nodejs/worker_threads'); ``` Workers are useful for performing CPU-intensive JavaScript operations; do not @@ -23,7 +23,7 @@ share memory efficiently by transferring `ArrayBuffer` instances or sharing ```js const { Worker, isMainThread, parentPort, workerData -} = require('worker_threads'); +} = require('@nodejs/worker_threads'); if (isMainThread) { module.exports = async function parseJSAsync(script) { @@ -104,7 +104,7 @@ yields an object with `port1` and `port2` properties, which refer to linked [`MessagePort`][] instances. ```js -const { MessageChannel } = require('worker_threads'); +const { MessageChannel } = require('@nodejs/worker_threads'); const { port1, port2 } = new MessageChannel(); port1.on('message', (message) => console.log('received', message)); @@ -243,8 +243,10 @@ Notable differences inside a Worker environment are: - The [`process.stdin`][], [`process.stdout`][] and [`process.stderr`][] may be redirected by the parent thread. -- The [`require('worker_threads').isMainThread`][] property is set to `false`. -- The [`require('worker_threads').parentPort`][] message port is available, +- The [`require('@nodejs/worker_threads').isMainThread`][] + property is set to `false`. +- The [`require('@nodejs/worker_threads').parentPort`][] message port is + available, - [`process.exit()`][] does not stop the whole program, just the single thread, and [`process.abort()`][] is not available. - [`process.chdir()`][] and `process` methods that set group or user ids @@ -286,7 +288,7 @@ the thread barrier. const assert = require('assert'); const { Worker, MessageChannel, MessagePort, isMainThread, parentPort -} = require('worker_threads'); +} = require('@nodejs/worker_threads'); if (isMainThread) { const worker = new Worker(__filename); const subChannel = new MessageChannel(); @@ -314,10 +316,10 @@ if (isMainThread) { * `eval` {boolean} If true, interpret the first argument to the constructor as a script that is executed once the worker is online. * `workerData` {any} Any JavaScript value that will be cloned and made - available as [`require('worker_threads').workerData`][]. The cloning will - occur as described in the [HTML structured clone algorithm][], and an error - will be thrown if the object cannot be cloned (e.g. because it contains - `function`s). + available as [`require('@nodejs/worker_threads').workerData`][]. The + cloning will occur as described in the [HTML structured clone algorithm][], + and an error will be thrown if the object cannot be cloned (e.g. because it + contains `function`s). * stdin {boolean} If this is set to `true`, then `worker.stdin` will provide a writable stream whose contents will appear as `process.stdin` inside the Worker. By default, no data is provided. @@ -356,7 +358,7 @@ added: v10.5.0 * `value` {any} The transmitted value The `'message'` event is emitted when the worker thread has invoked -[`require('worker_threads').postMessage()`][]. See the [`port.on('message')`][] +[`require('@nodejs/worker_threads').postMessage()`][]. See the [`port.on('message')`][] event for more details. ### Event: 'online' @@ -376,7 +378,7 @@ added: v10.5.0 * `transferList` {Object[]} Send a message to the worker that will be received via -[`require('worker_threads').parentPort.on('message')`][]. +[`require('@nodejs/worker_threads').parentPort.on('message')`][]. See [`port.postMessage()`][] for more details. ### worker.ref() @@ -451,7 +453,7 @@ added: v10.5.0 * {integer} An integer identifier for the referenced thread. Inside the worker thread, -it is available as [`require('worker_threads').threadId`][]. +it is available as [`require('@nodejs/worker_threads').threadId`][]. ### worker.unref()