This is only happening inside the next app. We're importing the node workers for a project, and we're getting errors in the console.
IMPORT CODE
// Core Modules
import { parentPort, workerData } from 'worker_threads';
CONSOLE ERROR
wait - compiling...
error - ./src/logic/DatabaseParser.ts:2:0
Module not found: Can't resolve 'worker_threads'
1 | // Core Modules
> 2 | import { parentPort, workerData } from 'worker_threads';
Import trace for requested module:
./src/components/templates/portal.template.tsx
./src/pages/index.tsx
https://nextjs.org/docs/messages/module-not-found
Before we get lost in the rabbit hole, the official Node.js docs now say to use node:worker_threads instead of just worker_threads.
// Core Modules
import { parentPort, workerData } from 'node:worker_threads';
Error in VS Code:
Cannot find module 'node:worker_threads' or its corresponding type declarations.ts(2307)
Recompiled error on save:
wait - compiling...
error - node:worker_threads
Module build failed: UnhandledSchemeError: Reading from "node:worker_threads" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
Import trace for requested module:
node:worker_threads
./src/logic/DatabaseParser.ts
./src/components/templates/portal.template.tsx
The "quick fix" in VS Code when using the node: prefix, was to install @types/node. But I've already got it installed.
"devDependencies": {
"@types/node": "^12.12.21",
}