pulsar-client-node icon indicating copy to clipboard operation
pulsar-client-node copied to clipboard

Cannot find module '[email protected]' by pnpm

Open JeffHu88 opened this issue 11 months ago • 2 comments

I tried to migrate an old project from NPM to PNPM, but after running pnpm install, when I try to start the project, I encounter a MODULE_NOT_FOUND error. How can I fix this issue?

node:internal/modules/cjs/loader:1247
  throw err;
  ^

Error: Cannot find module '/Users/user/Desktop/project/frontend-websocket-api/node_modules/.pnpm/[email protected]/node_modules/pulsar-client/lib/binding/pulsar.node'
Require stack:
- /Users/user/Desktop/project/frontend-websocket-api/node_modules/.pnpm/[email protected]/node_modules/pulsar-client/src/pulsar-binding.js
- /Users/user/Desktop/project/frontend-websocket-api/node_modules/.pnpm/[email protected]/node_modules/pulsar-client/index.js
- /Users/user/Desktop/project/frontend-websocket-api/dist/config/pulsar/pulsar.service.js
- /Users/user/Desktop/project/frontend-websocket-api/dist/gateway/pulsar-socket-frontend-service.js
- /Users/user/Desktop/project/frontend-websocket-api/dist/gateway/payment-pulsar-socket-impl/payment-pulsar-socket-impl.module.js
- /Users/user/Desktop/project/frontend-websocket-api/dist/gateway/gateway.module.js
- /Users/user/Desktop/project/frontend-websocket-api/dist/app.module.js
- /Users/user/Desktop/project/frontend-websocket-api/dist/main.js
    at Function._resolveFilename (node:internal/modules/cjs/loader:1244:15)
    at Function._load (node:internal/modules/cjs/loader:1070:27)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1335:12)
    at require (node:internal/modules/helpers:136:16)
    at Object.<anonymous> (/Users/user/Desktop/project/frontend-websocket-api/node_modules/.pnpm/[email protected]/node_modules/pulsar-client/src/pulsar-binding.js:24:17)
    at Module._compile (node:internal/modules/cjs/loader:1562:14)
    at Object..js (node:internal/modules/cjs/loader:1699:10)
    at Module.load (node:internal/modules/cjs/loader:1313:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/user/Desktop/project/frontend-websocket-api/node_modules/.pnpm/[email protected]/node_modules/pulsar-client/src/pulsar-binding.js',
    '/Users/user/Desktop/project/frontend-websocket-api/node_modules/.pnpm/[email protected]/node_modules/pulsar-client/index.js',
    '/Users/user/Desktop/project/frontend-websocket-api/dist/config/pulsar/pulsar.service.js',
    '/Users/user/Desktop/project/frontend-websocket-api/dist/gateway/pulsar-socket-frontend-service.js',
    '/Users/user/Desktop/project/frontend-websocket-api/dist/gateway/payment-pulsar-socket-impl/payment-pulsar-socket-impl.module.js',
    '/Users/user/Desktop/project/frontend-websocket-api/dist/gateway/gateway.module.js',
    '/Users/user/Desktop/project/frontend-websocket-api/dist/app.module.js',
    '/Users/user/Desktop/project/frontend-websocket-api/dist/main.js'
  ]
}

Node.js v22.13.1 pnpm v10.4.1

  • [x] Mac OS
  • [x] ubuntu

Cannot find module '[email protected]' by pnpm

JeffHu88 avatar Feb 18 '25 09:02 JeffHu88

I came across the same issue. When using pnpm the bindings don't get built automatically. You can fix this problem with the following workaround:

  1. Uninstall the pulsar-client pnpm uninstall pulsar-client

  2. Add the following post install script to your top level package.json of your pnpm workspace. Replace 1.12.0 with the pulsar-client with the version you are using.

  "scripts": {
    "postinstall": "cd ./node_modules/.pnpm/[email protected]/node_modules/pulsar-client && pnpm run install"
  },
  1. Install the pulsar-client with the version matching in your package.json pnpm install [email protected]

janik-io avatar Apr 29 '25 11:04 janik-io

I came across the same issue. When using pnpm the bindings don't get built automatically. You can fix this problem with the following workaround:

  1. Uninstall the pulsar-client pnpm uninstall pulsar-client
  2. Add the following post install script to your top level package.json of your pnpm workspace. Replace 1.12.0 with the pulsar-client with the version you are using.

"scripts": { "postinstall": "cd ./node_modules/.pnpm/[email protected]/node_modules/pulsar-client && pnpm run install" }, 3. Install the pulsar-client with the version matching in your package.json pnpm install [email protected]

Running into the same issue, and this fix worked thanks!

Any idea on the root cause of this? Does this logic need to move into postinstall step instead directly in pulsar-client?

mguay22 avatar Apr 30 '25 17:04 mguay22