Skip to content

Error: Cannot find module '../sentry_cpu_profiler-darwin-x64-115.node after bundling with rollup #13801

@ollebergkvist

Description

@ollebergkvist

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.32.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

instrument.mjs

import * as Sentry from '@sentry/node'
import { nodeProfilingIntegration } from '@sentry/profiling-node'

const { SENTRY_DSN } = process.env

Sentry.init({
  dsn: SENTRY_DSN,
  integrations: [nodeProfilingIntegration()],
  tracesSampleRate: 1.0,
  profilesSampleRate: 1.0
})

rollup.config.mjs

import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import sentryRollupPlugin from 'rollup-plugin-sentry'

const { SENTRY_ORG, SENTRY_PROJECT, SENTRY_AUTH_TOKEN } = process.env

/**
 * @type {import('rollup').RollupOptions}
 */
const config = {
  input: ['src/index.ts'],
  output: {
    dir: 'dist',
    format: 'cjs',
    sourcemap: true
  },
  plugins: [
    resolve({
      extensions: ['.ts', '.js', '.tsx', '.jsx', '.json', '.mjs', '.cjs']
    }),
    commonjs(),
    typescript(),
    json(),
    sentryRollupPlugin({
      org: SENTRY_ORG,
      project: SENTRY_PROJECT,
      authToken: SENTRY_AUTH_TOKEN,
      include: ['dist']
      //   ignore: ['node_modules']
    })
  ],
  onwarn(warning, handler) {
    if (warning.code === 'THIS_IS_UNDEFINED') {
      return
    }

    handler(warning)
  },
  external: []
}

export default config

Steps to Reproduce

  1. Bundle esm ts app to cjs with rollup
  2. Try to start bundled app

Expected Result

Should be able to instrument app.

Actual Result

Bundle log:

> rimraf dist && doppler run -- node --max-old-space-size=8192 ./node_modules/rollup/dist/bin/rollup -c


src/index.ts, instrument.mjs → dist...
> Found 132 release files
> Analyzing 132 sources
> Analyzing completed in 1.783s
> Rewriting sources
> Rewriting completed in 2.227s
> Adding source map references
> Bundling files for upload... ~/instrument.js.map
> Bundling completed in 3.292s
> Optimizing completed in 0.09s
> Uploading completed in 6.961s
> Uploaded release files to Sentry
> Processing completed in 0.152s
> File upload complete (processing pending on server)
> Organization: ***
> Project: api-crons
> Release: 6a4ba12474a52870a423ebe9d8be3e287f6a54aa
> Dist: None

Source Map Upload Report
  Scripts
    ~/BrowserWebSocketTransport-Ddg65Xcw.js
    ~/bidi-DOW30Uv-.js
    ~/birthday-Bao67xCe.js
    ~/emotion-cache.esm-BstkOBK6.js
    ~/emotion-react.esm-avPMztdr.js
    ~/emotion-server-create-instance.esm-Cznx7aFl.js
    ~/eniro-DSth4tx_.js
    ~/fastify-Sy475fAm.js
    ~/generate-scraper-DIJNZmbp.js
    ~/gmail-CYSZt0Mb.js
    ~/header-Dg-0p9bX.js
    ~/hitta-DvgVh9ob.js
    ~/index-0K98dy29.js
    ~/index-BLjzU1Xl.js
    ~/index-BXzztWaF.js
    ~/index-Cj4PlUlF.js
    ~/index-DKV-x1Wa.js
    ~/index-DVnrWFz_.js
    ~/index-DbKrt0bg.js
    ~/index-DcV_w5sG.js
    ~/index-OQo_UbwC.js
    ~/index-cPRKZTDI.js
    ~/index.js
    ~/instrument.js
    ~/merinfo-BReE3Mad.js
    ~/mrkoll-CjLOfrM5.js
    ~/multipart-parser-CvuNBLmD.js
    ~/ratsit-DV3xLxar.js
    ~/route-8A5tGn5K.js
    ~/route-B2ZQPAd1.js
    ~/route-B4aKHlHt.js
    ~/route-BAqvJRjH.js
    ~/route-Bb7zZLoK.js
    ~/route-Bfef0CEt.js
    ~/route-BqzwFOXA.js
    ~/route-Bvgs9Duq.js
    ~/route-BzC6nA-i.js
    ~/route-C1oSvstP.js
    ~/route-CIRgGVvT.js
    ~/route-CMJ-5iUX.js
    ~/route-CW752AWS.js
    ~/route-CaOJq1sJ.js
    ~/route-CeeRrJ9Y.js
    ~/route-CgNLC0a9.js
    ~/route-CjQGfRhU.js
    ~/route-Cph99weU.js
    ~/route-D0eaSXAI.js
    ~/route-D16PS9B1.js
    ~/route-DAMGHYse.js
    ~/route-DOisjE0j.js
    ~/route-Ds9rAoMI.js
    ~/route-YmGVU97L.js
    ~/route-cPrdabS6.js
    ~/route-dbXrPXYW.js
    ~/route-iIw7jkwO.js
    ~/route-oIW0tcyf.js
    ~/scraper-api-uvAhqNTy.js
    ~/stripe-W0Tps3wO.js
    ~/supabase-DOWx-MWN.js
    ~/typescript-DIEL7kn1.js
    ~/upplysning-BaXWcanx.js
    ~/websocket-server-QF6HvdS1.js
    ~/wrapper-D1DkkgNq.js
    ~/zod-CrTOooFA.js
  Minified Scripts
    ~/dayjs.min-BYrlO734.js (sourcemap at dayjs.min-BYrlO734.js.map)
    ~/https-CF0grQad.js (sourcemap at https-CF0grQad.js.map)
  Source Maps
    ~/BrowserWebSocketTransport-Ddg65Xcw.js.map
    ~/bidi-DOW30Uv-.js.map
    ~/birthday-Bao67xCe.js.map
    ~/dayjs.min-BYrlO734.js.map
    ~/emotion-cache.esm-BstkOBK6.js.map
    ~/emotion-react.esm-avPMztdr.js.map
    ~/emotion-server-create-instance.esm-Cznx7aFl.js.map
    ~/eniro-DSth4tx_.js.map
    ~/fastify-Sy475fAm.js.map
    ~/generate-scraper-DIJNZmbp.js.map
    ~/gmail-CYSZt0Mb.js.map
    ~/header-Dg-0p9bX.js.map
    ~/hitta-DvgVh9ob.js.map
    ~/https-CF0grQad.js.map
    ~/index-0K98dy29.js.map
    ~/index-BLjzU1Xl.js.map
    ~/index-BXzztWaF.js.map
    ~/index-Cj4PlUlF.js.map
    ~/index-DKV-x1Wa.js.map
    ~/index-DVnrWFz_.js.map
    ~/index-DbKrt0bg.js.map
    ~/index-DcV_w5sG.js.map
    ~/index-OQo_UbwC.js.map
    ~/index-cPRKZTDI.js.map
    ~/index.js.map
    ~/instrument.js.map
    ~/merinfo-BReE3Mad.js.map
    ~/mrkoll-CjLOfrM5.js.map
    ~/multipart-parser-CvuNBLmD.js.map
    ~/ratsit-DV3xLxar.js.map
    ~/route-8A5tGn5K.js.map
    ~/route-B2ZQPAd1.js.map
    ~/route-B4aKHlHt.js.map
    ~/route-BAqvJRjH.js.map
    ~/route-Bb7zZLoK.js.map
    ~/route-Bfef0CEt.js.map
    ~/route-BqzwFOXA.js.map
    ~/route-Bvgs9Duq.js.map
    ~/route-BzC6nA-i.js.map
    ~/route-C1oSvstP.js.map
    ~/route-CIRgGVvT.js.map
    ~/route-CMJ-5iUX.js.map
    ~/route-CW752AWS.js.map
    ~/route-CaOJq1sJ.js.map
    ~/route-CeeRrJ9Y.js.map
    ~/route-CgNLC0a9.js.map
    ~/route-CjQGfRhU.js.map
    ~/route-Cph99weU.js.map
    ~/route-D0eaSXAI.js.map
    ~/route-D16PS9B1.js.map
    ~/route-DAMGHYse.js.map
    ~/route-DOisjE0j.js.map
    ~/route-Ds9rAoMI.js.map
    ~/route-YmGVU97L.js.map
    ~/route-cPrdabS6.js.map
    ~/route-dbXrPXYW.js.map
    ~/route-iIw7jkwO.js.map
    ~/route-oIW0tcyf.js.map
    ~/scraper-api-uvAhqNTy.js.map
    ~/stripe-W0Tps3wO.js.map
    ~/supabase-DOWx-MWN.js.map
    ~/typescript-DIEL7kn1.js.map
    ~/upplysning-BaXWcanx.js.map
    ~/websocket-server-QF6HvdS1.js.map
    ~/wrapper-D1DkkgNq.js.map
    ~/zod-CrTOooFA.js.map
(!) Circular dependencies
node_modules/.pnpm/semver@7.6.3/node_modules/semver/classes/comparator.js -> node_modules/.pnpm/semver@7.6.3/node_modules/semver/classes/range.js -> node_modules/.pnpm/semver@7.6.3/node_modules/semver/classes/comparator.js
node_modules/.pnpm/@opentelemetry+sdk-trace-base@1.26.0_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/sdk-trace-base/build/esm/index.js -> node_modules/.pnpm/@opentelemetry+sdk-trace-base@1.26.0_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/sdk-trace-base/build/esm/BasicTracerProvider.js -> node_modules/.pnpm/@opentelemetry+sdk-trace-base@1.26.0_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/sdk-trace-base/build/esm/index.js
node_modules/.pnpm/acquerello@2.0.8/node_modules/acquerello/dist/index.js -> node_modules/.pnpm/acquerello@2.0.8/node_modules/acquerello/dist/styles.js -> node_modules/.pnpm/acquerello@2.0.8/node_modules/acquerello/dist/index.js
...and 62 more
(!) [plugin node-resolve] preferring built-in module 'process' over local alternative at '/Users/o../api/node_modules/.pnpm/process@0.11.10/node_modules/process/index.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning.or passing a function to 'preferBuiltins' to provide more fine-grained control over which built-in modules to prefer.
(!) [plugin node-resolve] preferring built-in module 'events' over local alternative at '/Users/../node_modules/.pnpm/events@3.3.0/node_modules/events/events.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning.or passing a function to 'preferBuiltins' to provide more fine-grained control over which built-in modules to prefer.
(!) [plugin node-resolve] preferring built-in module 'string_decoder' over local alternative at '/Users/../node_modules/.pnpm/string_decoder@1.3.0/node_modules/string_decoder/lib/string_decoder.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning.or passing a function to 'preferBuiltins' to provide more fine-grained control over which built-in modules to prefer.
(!) [plugin node-resolve] preferring built-in module 'buffer' over local alternative at '/Users/../api/node_modules/.pnpm/buffer@5.7.1/node_modules/buffer/index.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning.or passing a function to 'preferBuiltins' to provide more fine-grained control over which built-in modules to prefer.
(!) [plugin node-resolve] preferring built-in module 'punycode' over local alternative at '/Users/../api/node_modules/.pnpm/punycode@2.3.1/node_modules/punycode/punycode.es6.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning.or passing a function to 'preferBuiltins' to provide more fine-grained control over which built-in modules to prefer.
(!) Use of eval is strongly discouraged
https://rollupjs.org/troubleshooting/#avoiding-eval
node_modules/.pnpm/@protobufjs+inquire@1.1.0/node_modules/@protobufjs/inquire/index.js
10: function inquire(moduleName) {
11:     try {
12:         var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
                      ^
13:         if (mod && (mod.length || Object.keys(mod).length))
14:             return mod;
created dist in 2m 9.4s

Error when trying to run the bundled app:

> doppler run -- node -r source-map-support ./dist/index.js

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

Error: Cannot find module '../sentry_cpu_profiler-darwin-x64-115.node'
Require stack:
- /Users/../api/dist/instrument.js
- /Users/../api/dist/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1225:15)
    at Module._load (node:internal/modules/cjs/loader:1051:27)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at importCppBindingsModule (/Users/../api/dist/instrument.js:47714:16)
    at Object.<anonymous> (/Users/../api/dist/instrument.js:47819:36)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/../api/dist/instrument.js',
    '/Users/../api/dist/index.js'
  ]
}

Node.js v20.17.0
 ELIFECYCLE  Command failed with exit code 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPackage: nodeIssues related to the Sentry Node SDK

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions