grafana / pyroscope

Continuous Profiling Platform. Debug performance issues down to a single line of code
https://grafana.com/oss/pyroscope/
GNU Affero General Public License v3.0
9.9k stars 585 forks source link

NodeJS cannot find module regenerator-runtime/runtime #1909

Closed BryanHunt closed 1 year ago

BryanHunt commented 1 year ago

We are attempting to add Pyroscope to one of our NodeJS framework modules. Pyroscope fails to load with the following error:

Error: Cannot find module '/Users/bhunt/Development/*****/modules/microservice/node_modules/regenerator-runtime/runtime' imported from /Users/bhunt/Development/*****/modules/microservice/node_modules/@pyroscope/nodejs/dist/esm/index.js
    at finalizeResolution (/Users/bhunt/Development/*****/modules/microservice/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:366:11)
    at moduleResolve (/Users/bhunt/Development/*****/modules/microservice/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:801:10)
    at Object.defaultResolve (/Users/bhunt/Development/*****/modules/microservice/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:912:11)
    at /Users/bhunt/Development/*****/modules/microservice/node_modules/ts-node/src/esm.ts:218:35
    at entrypointFallback (/Users/bhunt/Development/*****/modules/microservice/node_modules/ts-node/src/esm.ts:168:34)
    at /Users/bhunt/Development/*****/modules/microservice/node_modules/ts-node/src/esm.ts:217:14
    at addShortCircuitFlag (/Users/bhunt/Development/*****/modules/microservice/node_modules/ts-node/src/esm.ts:409:21)
    at resolve (/Users/bhunt/Development/*****/modules/microservice/node_modules/ts-node/src/esm.ts:197:12)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36)

We are running NodeJS v16.19.1 with the following mocha configuration:

{
  "mocha": {
    "reporter": "mocha-multi-reporters",
    "reporter-options": [
      "configFile=mocha-reporter-config.json"
    ],
    "loader": "ts-node/esm"
  }
}
jpettit commented 1 year ago

The import also appears to be incorrect for esm, omitting the .js portion.

BryanHunt commented 1 year ago

Yes, hacking the module and changing the import to:

import 'regenerator-runtime/runtime.js';

works around this problem. I can't find this source code anywhere in this repository; otherwise, I would submit a PR.

BryanHunt commented 1 year ago

Found the code. It is in a different repo: https://github.com/grafana/pyroscope-nodejs/blob/main/src/index.ts. I will move this issue there.

https://github.com/grafana/pyroscope-nodejs/issues/32