Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endless issues of Error: Cannot find module '....\.next\server\vendor-chunks\lib\worker.js' #68950

Open
jdoe802 opened this issue Aug 15, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template. Output (export/standalone) Related to the the output option in `next.config.js`. Webpack Related to Webpack with Next.js.

Comments

@jdoe802
Copy link

jdoe802 commented Aug 15, 2024

Link to the code that reproduces this issue

https://github.com/jdoe802/pino-pretty-mongo-minimal

To Reproduce

have been working on this for a few weeks now. I was getting errors like the following when trying to implement pino transport

⨯ uncaughtException: Error: Cannot find module 'C:\Users\<redact>\.next\server\vendor-chunks\lib\worker.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
    at MessagePort.<anonymous> (node:internal/main/worker_thread:186:26)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:820:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28) {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
Error: the worker thread exited
    at Worker.onWorkerExit (webpack-internal:///(ssr)/./node_modules/thread-stream/index.js:201:32)
    at Worker.emit (node:events:519:28)
    at [kOnExit] (node:internal/worker:315:10)
    at Worker.<computed>.onexit (node:internal/worker:229:20)
    at Worker.callbackTrampoline (node:internal/async_hooks:130:17)
 ⨯ node_modules\thread-stream\index.js (201:0) @ Worker.onWorkerExit
 ⨯ uncaughtException: Error: the worker thread exited
    at Worker.onWorkerExit (webpack-internal:///(ssr)/./node_modules/thread-stream/index.js:201:32)
    at Worker.emit (node:events:519:28)
    at [kOnExit] (node:internal/worker:315:10)
    at Worker.<computed>.onexit (node:internal/worker:229:20)
    at Worker.callbackTrampoline (node:internal/async_hooks:130:17)

this originally seemed to be fixed with the following workaround being added to the next.config file: (the worker.js file, indexes file, and wait file were all copied from /node_modules/thread-stream/ folder)

function pinoWebpackAbsolutePath(relativePath) {
    console.log("relativepath:" + relativePath + " dirname:" +  __dirname);
    console.log(path.resolve(__dirname, relativePath));
    return path.resolve(__dirname, relativePath);
}

globalThis.__bundlerPathsOverrides = {
    'thread-stream-worker': pinoWebpackAbsolutePath('./worker.js'),
    'indexes': pinoWebpackAbsolutePath('./indexes.js'),
    'wait': pinoWebpackAbsolutePath('./wait.js'),
  };

however after further inspection some logs were outputting correctly with pino transport and others were causing this message

Error: Cannot find module 'C:\Users\<redact>\.next\server\vendor-chunks\lib\worker.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
    at MessagePort.<anonymous> (node:internal/main/worker_thread:186:26)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:820:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:820:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)
    at MessagePort.callbackTrampoline (node:internal/async_hooks:130:17)
    at [kOnExit] (node:internal/worker:304:5)
    at Worker.<computed>.onexit (node:internal/worker:229:20)
    at Worker.callbackTrampoline (node:internal/async_hooks:130:17) {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

The logging transport that is triggering all these issues:

import pino, {Logger} from "pino";

export const masterLogger = pino({
    level: `${process.env.NEXT_PUBLIC_PINO_LOG_LEVEL ?? "debug"}`,
    redact: ['email', 'profileName', 'password', 'address'],
    //timestamp: () => `",timestamp":"${new Date(Date.now()).toISOString()}"`,
    transport: {
        target: 'pino-mongodb',
        options: {
            uri: process.env.MONGODB_URI,
            database: 'dev',
            collection: 'log-collection',
        },
    },
});

masterLogger.info('hello');

I've tried multiple solutions (commented out in the repo) Overall it is logging in some places but not in others in my full code repo. It logs to console in all files when I don't add the transport streams. After adding the transport streams and multiple workarounds, getting this. If next could just update their files so that worker.js was properly found in the first place many issues would be avoided.

Current vs. Expected behavior

I expected the logging to work without throwing worker.js related issues

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Enterprise
Binaries:
  Node: 20.16.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.1.3
  eslint-config-next: 14.1.3
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Output (export/standalone), Webpack

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

This issue is happening locally .

@jdoe802 jdoe802 added the bug Issue was opened via the bug report template. label Aug 15, 2024
@github-actions github-actions bot added Output (export/standalone) Related to the the output option in `next.config.js`. Webpack Related to Webpack with Next.js. labels Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Output (export/standalone) Related to the the output option in `next.config.js`. Webpack Related to Webpack with Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant