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

ESM: import Sentry from "@sentry/node" #211

Open
tobiasmuehl opened this issue Feb 18, 2024 · 2 comments
Open

ESM: import Sentry from "@sentry/node" #211

tobiasmuehl opened this issue Feb 18, 2024 · 2 comments

Comments

@tobiasmuehl
Copy link

tobiasmuehl commented Feb 18, 2024

Environment

https://stackblitz.com/edit/stackblitz-starters-gpqjnv?file=index.ts&view=editor

Reproduction

In stackblitz terminal: npx jiti index.ts

Describe the bug

❯ npx jiti index.ts
Need to install the following packages:
jiti@1.21.0
Ok to proceed? (y) y
TypeError: Cannot read properties of undefined (reading 'init')
    at eval (file:///home/projects/stackblitz-starters-gpqjnv/index.ts:3:15)
    at evalModule (file:///home/.npm/_npx/dd8909d1e5fe7d01/node_modules/jiti/dist/jiti.js:1:256518)
    at jiti (file:///home/.npm/_npx/dd8909d1e5fe7d01/node_modules/jiti/dist/jiti.js:1:254446)
    at Object.eval (file:///home/.npm/_npx/dd8909d1e5fe7d01/node_modules/jiti/bin/jiti.js:14:1)
    at Object.function (https://stackblitzstartersgpqjnv-p5nm.w-credentialless.staticblitz.com/blitz.a9c8a5a3.js:352:194797)
    at Module._compile (https://stackblitzstartersgpqjnv-p5nm.w-credentialless.staticblitz.com/blitz.a9c8a5a3.js:54:14871)
    at Module._extensions..js (https://stackblitzstartersgpqjnv-p5nm.w-credentialless.staticblitz.com/blitz.a9c8a5a3.js:54:15550)
    at Module.load (https://stackblitzstartersgpqjnv-p5nm.w-credentialless.staticblitz.com/blitz.a9c8a5a3.js:54:13457)
    at Module._load (https://stackblitzstartersgpqjnv-p5nm.w-credentialless.staticblitz.com/blitz.a9c8a5a3.js:54:10535)
    at Function.executeUserEntryPoint [as runMain] (https://stackblitzstartersgpqjnv-p5nm.w-credentialless.staticblitz.com/blitz.a9c8a5a3.js:125:731)

Additional context

It can be fixed by fixing the imports, for example

import { init as sentryInit } from "@sentry/node"

sentryInit()

Logs

No response

@peterroe
Copy link

This looks to be a problem of usage with the CJS/ESM, I think there are two way to solve your problem:

  1. Use require syntax with CJS.
const Sentry = require('@sentry/node');
  1. Use import * as syntax with ESM.
import * as Sentry from '@sentry/node';

@tobiasmuehl
Copy link
Author

require doesn't play nicely with VSCode/intellisense. In the stackblitz example the import * as seems to work, but it doesn't work in my actual app. I will investigate further.

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

No branches or pull requests

2 participants