getsentry / getsentry/sentry-javascript

TypeScript w/ esModuleInterop: `import Sentry from "@sentry/{node|browser}"` is not an error, but does not work.

Aberta
#3,105 18 comentários 25 reações 1 responsável Ver no GitHub

@lforst já está trabalhando nisso.

Desde 14/1/2025.

Bug
Linguagem predominante
TypeScript
Estrelas
8.7k
Forks
1.8k
Merge médio
1d 18h
PRs com merge (30d)
541

Descrição

Relates to PR https://github.com/getsentry/sentry-javascript/pull/3077

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:
Version:
5.29.0

Description

Sentry must be imported using import * as Sentry instead of import Sentry in order to work.
With the esModuleInterop compiler option enabled, TypeScript does not complain about import Sentry.
(With the option off, TS recognizes that the module does not have a default import and forbids import Sentry)

This appears to be because the Sentry index.js module declares __esModule: true but does not actually have a value for the default export:

 // import Sentry from "@sentry/node" - transpiled
 node_1 = tslib_1.__importDefault(node_1);

 //tslib
 __importDefault = function (mod) {
        return (mod && mod.__esModule) ? mod : { "default": mod };
    };

Can the library be updated so the default import works as TypeScript thinks it does?
This is only an issue when the esModuleInterop setting is on, but it's a pretty valuable setting and a dangerous mistake
for the developer.

// Either 
// vv - Can this be added?
exports.default = exports;

// Or
// vv - Can this be removed?  Though it would make the `import *` less efficient. 
Object.defineProperty(exports, "__esModule", { value: true });

Thanks!

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.