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

Import error when using worker with pkg #1948

Closed
nagyszabi opened this issue Apr 24, 2024 · 1 comment · Fixed by #1949
Closed

Import error when using worker with pkg #1948

nagyszabi opened this issue Apr 24, 2024 · 1 comment · Fixed by #1949

Comments

@nagyszabi
Copy link
Contributor

Hi there!

When using pkg (more specifically yao-pkg) the transport stream builder is unable to load files.
This is happening on node v20 while using CommonJS modules throughout the whole project, and it's throwing the following error:

TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
    at importModuleDynamicallyCallback (node:internal/modules/esm/utils:213:9)
    at eval (eval at <anonymous> (C:\snapshot\backend\node_modules\real-require\src\index.js:4:20), <anonymous>:3:1)
    at loadTransportStreamBuilder (C:\snapshot\backend\node_modules\pino\lib\transport-stream.js:28:19)
    at C:\snapshot\backend\node_modules\pino\lib\worker.js:14:22
    at Array.map (<anonymous>)
    at C:\snapshot\backend\node_modules\pino\lib\worker.js:13:39
    at start (C:\snapshot\backend\node_modules\thread-stream\lib\worker.js:61:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on ThreadStream instance at:
    at Immediate.<anonymous> (C:\snapshot\backend\node_modules\thread-stream\index.js:369:12)
    at process.processImmediate (node:internal/timers:478:21)

Node.js v20.11.1

This is essentially the same issue I encountered in the thread-stream package.

And just like in the other issue, adding the ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING error code here fixes the problem:

else if (error.code === undefined || error.code === 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING') {
      // When bundled with pkg, an undefined error is thrown when called with realImport
      fn = realRequire(decodeURIComponent(target))
}

I am working on creating a PR with the same fix as I did for thread-stream.

@mcollina
Copy link
Member

Go for it! Also add a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants