#Next.js Core Imports Throwing Error

12 messages · Page 1 of 1 (latest)

grizzled veldt
#

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",
}
merry ibex
grizzled veldt
merry ibex
grizzled veldt
#

You might need to expand on that. The entire project is in Node.

merry ibex
#

The entire project is not in node. In fact, I'd wager that the vast majority of it isn't.

grizzled veldt
#

I've also run through countless solutions on stack overflow, they many of them talk about using a next config file. Which I've added in multiple variations.

#

I'm guessing that the class component is screwing this up.

grizzled veldt
#

Any ideas?