sentry-electron icon indicating copy to clipboard operation
sentry-electron copied to clipboard

mod.require is not a function after enable ANR

Open PayneFuRC opened this issue 1 year ago • 6 comments

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)

Electron SDK Version

4.17.0

Electron Version

27.2.0

What platform are you using?

MacOS

Link to Sentry event

https://jupiter-ct.sentry.io/discover/desktop-development:da239c05e8f94e2da9c986d56d147597/?field=title&field=event.type&field=project&field=user.display&field=timestamp&field=replayId&homepage=true&name=All+Events&project=1428302&query=&sort=-timestamp&statsPeriod=1h&yAxis=count%28%29

Steps to Reproduce

  1. enable main process anr in our company code
init({
  dsn: '__DSN__',
  debug: true,
  onFatalError: () => {},
  integrations: [new Integrations.Anr({ captureStackTrace: true, anrThreshold: 1000 })],
});
  1. compile and webpack
  2. open the app, then there's an error
TypeError: mod.require is not a function
  File "main.js", line 48350, col 14, in dynamicRequire
  File "main.js", line 43455, col 41, in getWorkerThreads
  File "main.js", line 43540, col 22, in _startWorker

I have tried the method in #92, but it still doesn't work.

Expected Result

No error

Actual Result

There's an error

TypeError: mod.require is not a function
  File "main.js", line 48350, col 14, in dynamicRequire
  File "main.js", line 43455, col 41, in getWorkerThreads
  File "main.js", line 43540, col 22, in _startWorker

PayneFuRC avatar Feb 18 '24 06:02 PayneFuRC

If you're using a bundler you'll likely need to import differently for the main/renderer: https://docs.sentry.io/platforms/javascript/guides/electron/#bundler-configuration

This will become the default in the next major version.

timfish avatar Feb 18 '24 14:02 timfish

@timfish I have imported differently for the main/renderer, but it still doesn't work.

PayneFuRC avatar Feb 19 '24 00:02 PayneFuRC

Ah sorry I understand the issue now. This dynamicRequire is used to workaround node compatibility issues but appears to cause issues with webpack.

timfish avatar Feb 19 '24 15:02 timfish

@timfish any progress?

PayneFuRC avatar Apr 09 '24 06:04 PayneFuRC

Removing use of dynamicRequire is a breaking change and has been removed in the next major version (v5) which is currently being worked on.

timfish avatar Apr 09 '24 09:04 timfish

There is a beta available of v5 of the Electron SDK which uses v8 of the JavaScript SDKs. dynamicRequire is no longer used in this version.

timfish avatar May 03 '24 09:05 timfish

v5.0.0 of the Electron SDK has now been released which uses v8 of the JavaScript SDKs with improved ESM support and no use of dynamicRequire.

Feel free to open a new issue if problems still persist!

timfish avatar May 21 '24 15:05 timfish