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

SDK does not support ESM in main process #751

Closed
3 tasks done
mahnunchik opened this issue Sep 25, 2023 · 9 comments
Closed
3 tasks done

SDK does not support ESM in main process #751

mahnunchik opened this issue Sep 25, 2023 · 9 comments
Assignees

Comments

@mahnunchik
Copy link

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Electron SDK Version

4.11.0

Electron Version

28

What platform are you using?

MacOS

Link to Sentry event

No response

Steps to Reproduce

Electron 28 with ESM support

Expected Result

Named export is supported as it shown in the readme

import { init } from '@sentry/electron';

init({
  dsn: '__DSN__',
  // ...
});

Actual Result

SyntaxError: Named export 'init' not found. The requested module '@sentry/electron' is a CommonJS module, which may not support all module.exports as named exports.

@mahnunchik
Copy link
Author

It seems @sentry/electron is completely broken when exported as ESM module in native ESM environment.

import Sentry from '@sentry/electron';
node_modules/@sentry/electron/esm/main/index.js:1
import { ensureProcess } from '../common';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1185:20)
    at Module._compile (node:internal/modules/cjs/loader:1227:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1326:10)
    at Module.load (node:internal/modules/cjs/loader:1126:32)
    at Module._load (node:internal/modules/cjs/loader:967:12)
    at f._load (node:electron/js2c/asar_bundle:2:13542)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

@mahnunchik
Copy link
Author

@timfish I can not use sentry with Electron 28 in ESM environment. It is impossible to import cjs version due to exports field in package.json

Could it be fixed?

@timfish
Copy link
Collaborator

timfish commented Sep 25, 2023

It was on the list to test but I wasn't aware of a release yet since v27 is still in beta.
#730

I see there's a nightly. Is that what you're using?

It should be relatively easy to fix and I need to add some integration tests too.

@mahnunchik
Copy link
Author

Yes, I'm using nightly Electron 28 electron/electron#37535 (comment) to have ESM only code.

@timfish timfish changed the title Named export 'init' not found SDK does not support ESM in main process Sep 27, 2023
@timfish timfish self-assigned this Sep 27, 2023
@timfish
Copy link
Collaborator

timfish commented Oct 2, 2023

This should be working in 4.12.0 but it won't be fully tested until there's a beta release that we can run through the full test suite.

@timfish timfish closed this as completed Oct 2, 2023
@thomasbadera
Copy link

this seems to be broken again in 4.17+

@timfish
Copy link
Collaborator

timfish commented Feb 29, 2024

this seems to be broken again in 4.17+

We test the latest versions of Electron with ESM in the main process. Can you open an issue with some reproduction steps?

@thomasbadera
Copy link

this seems to be broken again in 4.17+

We test the latest versions of Electron with ESM in the main process. Can you open an issue with some reproduction steps?

unfortunately it's not very consistent, I have two electron apps... one where it's working and one where I get

App threw an error during load SyntaxError: Cannot use import statement outside a module at ../../node_modules/@sentry-internal/tracing/esm/node/integrations/mysql.js

both apps have identical tsconfigs, same sentry versions, same usage

@timfish
Copy link
Collaborator

timfish commented Feb 29, 2024

Can you open a new issue with the full stack trace?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants