evanw / evanw/node-source-map-support

Cannot find module when `import "source-map-support/register"`

Open
#307 2 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.2k
Forks
223
PR merge metrics
No merged PRs in 30d

Description

When using `import "source-map-support/register"` on Typescript 4.5.5 with `"module": "ES2020"` and `"type": "module"`, I see :

```
/.../node_modules/ts-node/dist-raw/node-esm-resolve-implementation.js:383
throw new ERR_MODULE_NOT_FOUND(
^
CustomError: Cannot find module '/.../node_modules/source-map-support/register' imported from /.../packages/backend/src/cdk.ts
at finalizeResolution (/.../node_modules/ts-node/dist-raw/node-esm-resolve-implementation.js:383:11)
at moduleResolve (/.../node_modules/ts-node/dist-raw/node-esm-resolve-implementation.js:818:10)
at Object.defaultResolve (/.../node_modules/ts-node/dist-raw/node-esm-resolve-implementation.js:929:11)
at resolve (/.../node_modules/ts-node/src/esm.ts:163:38)
at ESMLoader.resolve (node:internal/modules/esm/loader:422:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40)
at ModuleWrap. (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36)
```

Root entry point import works without issues:

```typescript
import sourceMapSupport from "source-map-support";
sourceMapSupport.install();
```

According to [Typescript docs](https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta/#esm-nodejs) `package.json` might need explicit `"exports"` with `"types"` for the `register` entry point.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the `source-map-support/register` import with TypeScript 4.5.5, `module: ES2020`, and `type: module`, then inspect the package metadata and ESM resolution behavior. Compare it with the working root `source-map-support` import; done means the `register` entry point resolves successfully in the reported setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, typescript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.