nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.46k stars 279 forks source link

thread error: Error: Module did not self-register #4180

Closed CKzcb closed 3 months ago

CKzcb commented 1 year ago

Version

18.15.0

Platform

win

Subsystem

No response

What steps will reproduce the bug?

const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
const msgpack = require('msgpack');

// 在主线程中创建消息对象
const dataToSend = { message: 'Hello from main thread!' };
const encodedData = msgpack.pack(dataToSend);

if (isMainThread) {
  // 主线程
  // 创建子线程
  const worker = new Worker(__filename, { workerData: encodedData });

  // 监听子线程的消息
  worker.on('message', (encodedMessage) => {
    // 解码消息
    const decodedMessage = msgpack.unpack(encodedMessage);
    console.log('Received message from worker:', decodedMessage);
  });

  // 发送消息给子线程
  worker.postMessage(encodedData);
} else {
  // 子线程
  // 监听主线程的消息
  parentPort.on('message', (encodedMessage) => {
    // 解码消息
    const decodedMessage = msgpack.unpack(encodedMessage);
    console.log('Received message from main thread:', decodedMessage);

    // 在子线程中创建上下文相关的数据
    const responseData = { message: 'Hello from worker thread!' };

    // 编码并发送消息给主线程
    const encodedResponse = msgpack.pack(responseData);
    parentPort.postMessage(encodedResponse);
  });
}

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

No response

What do you see instead?

[ERROR] default - thread error: Error: Module did not self-register: 'xxxxxx\node_modules\msgpack\build\Release\msgpackBinding.node'.
    at Module._extensions..node (node:internal/modules/cjs/loader:1338:18)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19)       
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (H:\company\sg2\tsgf\node_modules\msgpack\lib\msgpack.js:6:14)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)      
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12) {        
  code: 'ERR_DLOPEN_FAILED'
}

Additional information

The error occurred when i use msgpack in worker-thread, how to solve

preveen-stack commented 1 year ago

pls share msgpack version and the windows version

CKzcb commented 1 year ago

pls share msgpack version and the windows version

msgpack@1.0.3 Microsoft Windows NT 10.0.19045.0 x64

preveen-stack commented 1 year ago

are you able to reproduce the issue with just the code below

const msgpack = require('msgpack');

Also, can you try uninstalling and reinstalling msgpack and share the installlog

github-actions[bot] commented 4 months ago

It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] commented 3 months ago

It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.