简体   繁体   中英

ReferenceError: Worker is not defined in fresh Nextjs project

I'm investigating a larger issue where I am trying to import a webpacked javascript file into a NextJS project that uses Worker and keep getting ReferenceError: Worker is not defined . I've minimized it to the following:

  • Create a fresh NextJS project with npx create-next-app@latest
  • Inside that project, create a javascript file containing just the following line: module.exports = Worker;
  • Go to pages/_app.js and try to import the file we just created in the previous step const shouldThrow = require('../myFile.js') .
  • Run npm run build , should now throw ReferenceError: Worker is not defined

Why does this happen and how can I fix it?

If you check docs

const { Worker } = require("node:worker_threads");

console.log("W", Worker);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM