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

Named export 'tracer' not found in runtime #4814

Open
vubogovich opened this issue Oct 23, 2024 · 0 comments
Open

Named export 'tracer' not found in runtime #4814

vubogovich opened this issue Oct 23, 2024 · 0 comments

Comments

@vubogovich
Copy link

import { tracer } from 'dd-trace'; added automatically by VS Code fails in runtime with:

import { tracer } from "dd-trace";
         ^^^^^^
SyntaxError: Named export 'tracer' not found. The requested module 'dd-trace' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'dd-trace';
const { tracer } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:146:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:229:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:473:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)

Node.js v20.18.0

import tracer from 'dd-trace'; works well, also suggested by VS Code and the only import added automatically by WebStorm.

The critical part of the bug is the wrong import is not caught by TypeScript at the time of compilation so it's easy to break the production.

Seems to be related to #4070 (CC @Qard). Tested on lambda x86_64 and Windows 11.

[email protected]
[email protected]
[email protected]
package.json with "type": "module"

tsconfig.json:

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "module": "node16",
    "moduleResolution": "node16",
    "lib": ["es2023"],
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "target": "es2022",
    "strict": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "outDir": "build"
  },
  "include": ["src"]
}

Transpiled code:

// Added automatically by VS Code
import { tracer } from "dd-trace";
tracer.init();

Minimal reproducible example

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

1 participant