sentry-javascript
sentry-javascript copied to clipboard
TypeError when ANR is enabled in a bundled application
Is there an existing issue for this?
- [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- [X] I have reviewed the documentation https://docs.sentry.io/
- [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
7.112.2
Framework Version
No response
Link to Sentry event
No response
SDK Setup
Sentry.init({
dsn: DSN,
integrations: (defaults) =>
defaults.concat(
new Sentry.Integrations.Anr({
captureStackTrace: true,
anrThreshold: 1000,
})
),
});
Steps to Reproduce
- Enable ANR integration in Sentry
- Bundle Node.JS application using esbuild
- Start your application
Esbuild configuration:
require("esbuild").build({
sourcemap: "linked",
bundle: true,
minify: true,
keepNames: true,
platform: "node",
outfile: "dist/index.js",
entryPoints: ["src/index.ts"],
external: [
"@sentry/profiling-node",
]
});
Expected Result
No TypeError exception should be thrown when ANR is enabled in a bundled application.
Actual Result
Bundled application throws an exception on application start when ANR is enabled:
TypeError: t.require is not a function
File "/app/node_modules/@sentry/src/node.ts", line 30, col 14, in Object.dynamicRequire
File "/app/node_modules/@sentry/src/integrations/anr/index.ts", line 65, col 31, in getWorkerThreads
File "/app/node_modules/@sentry/src/integrations/anr/index.ts", line 209, col 31, in _startWorker
Error title in Sentry TypeError (Object.dynamicRequire(@sentry.src:node.ts).
Logs from application:
Debugger listening on ws://127.0.0.1:40097/27e0245a-3b48-4536-839e-e4faec129e2a
For help, see: https://nodejs.org/en/docs/inspector
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
TypeError: t.require is not a function
at Object.dynamicRequire (/app/dist/index.js:5:14173)
at getWorkerThreads (/app/dist/index.js:33:194972)
at _startWorker (/app/dist/index.js:33:196411)
@ollipa are you using ESM or CJS?
@AbhiPrasad we use CJS.
I tried disabling minification but that didn't help. Stack trace changed a bit:
TypeError: mod3.require is not a function
at Object.dynamicRequire (/app/dist/index.js:1969:19)
at getWorkerThreads (/app/dist/index.js:17289:20)
at _startWorker (/app/dist/index.js:17376:35)
https://github.com/getsentry/sentry-javascript/blob/1d3469d569d2112d7926b04a8da950d68189e7c5/packages/node/src/integrations/anr/index.ts#L65
Is module available in the context? What does typeof module.require emit?
This code:
console.log("module--->");
console.log(typeof module.require);
console.log("<---module");
Outputs:
module--->
function
<---module
Hmm not quite sure what it could be then, @timfish have you seen something like this before?
No, not sure what's causing this.
In the next major, dynamicRequire is no longer used.
I can test this with the new major version when it is out of beta and report back
If you want, you can already install the latest beta and try it (beta.5 should be available today or tomorrow). This version is already quite stable.
8.0 is out!
See: https://docs.sentry.io/platforms/javascript/guides/node/migration/v7-to-v8/
This should fix this so closing, but please re-open if the issue still occurs. Thanks!