Es import @sentry/node fails without default export

#1

I use ES import to resolve sentry like:

import Sentry from '@sentry/node';

This code is processed via babel and compiled to:

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};

const node_1 = __importDefault(require("@sentry/node"));

It’s interesting that sentry’s node SDK exports an object with __esModule = true but without a default property:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var types_1 = require("@sentry/types");
exports.Severity = types_1.Severity;
exports.Status = types_1.Status;
var core_1 = require("@sentry/core");
exports.addGlobalEventProcessor = core_1.addGlobalEventProcessor;
exports.addBreadcrumb = core_1.addBreadcrumb;
exports.captureException = core_1.captureException;
exports.captureEvent = core_1.captureEvent;
exports.captureMessage = core_1.captureMessage;
exports.configureScope = core_1.configureScope;
exports.getCurrentHub = core_1.getCurrentHub;
exports.getHubFromCarrier = core_1.getHubFromCarrier;
exports.Hub = core_1.Hub;
exports.Scope = core_1.Scope;
exports.withScope = core_1.withScope;
var client_1 = require("./client");
exports.NodeClient = client_1.NodeClient;
var sdk_1 = require("./sdk");
exports.defaultIntegrations = sdk_1.defaultIntegrations;
exports.init = sdk_1.init;
exports.flush = sdk_1.flush;
exports.close = sdk_1.close;
var version_1 = require("./version");
exports.SDK_NAME = version_1.SDK_NAME;
exports.SDK_VERSION = version_1.SDK_VERSION;
var core_2 = require("@sentry/core");
var Handlers = require("./handlers");
exports.Handlers = Handlers;
var NodeIntegrations = require("./integrations");
var Transports = require("./transports");
exports.Transports = Transports;
var INTEGRATIONS = tslib_1.__assign({}, core_2.Integrations, NodeIntegrations);
exports.Integrations = INTEGRATIONS;
//# sourceMappingURL=index.js.map

In this case @sentry/node resolve to exports.default property and got undefined finally, causing init() to fail.

I’m using typescript so it’s not a good practice to change import to require, sentry’s node SDK seems not conforming to the well-known __esModule convention.

#2

It seems I should import * as Sentry from '@sentry/node';