Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when ANR is enabled in a bundled application #11771

Open
3 tasks done
ollipa opened this issue Apr 24, 2024 · 8 comments
Open
3 tasks done

TypeError when ANR is enabled in a bundled application #11771

ollipa opened this issue Apr 24, 2024 · 8 comments

Comments

@ollipa
Copy link

ollipa commented Apr 24, 2024

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

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

  1. Enable ANR integration in Sentry
  2. Bundle Node.JS application using esbuild
  3. 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)
@AbhiPrasad
Copy link
Member

@ollipa are you using ESM or CJS?

@ollipa
Copy link
Author

ollipa commented Apr 24, 2024

@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)

@AbhiPrasad
Copy link
Member

return dynamicRequire(module, 'worker_threads');

Is module available in the context? What does typeof module.require emit?

@ollipa
Copy link
Author

ollipa commented Apr 24, 2024

This code:

console.log("module--->");
console.log(typeof module.require);
console.log("<---module");

Outputs:

module--->
function
<---module

@AbhiPrasad
Copy link
Member

Hmm not quite sure what it could be then, @timfish have you seen something like this before?

@timfish
Copy link
Collaborator

timfish commented Apr 24, 2024

No, not sure what's causing this.

In the next major, dynamicRequire is no longer used.

@ollipa
Copy link
Author

ollipa commented Apr 30, 2024

I can test this with the new major version when it is out of beta and report back

@s1gr1d
Copy link
Member

s1gr1d commented Apr 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

4 participants