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

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

Open
shishkin opened this issue Feb 9, 2022 · 2 comments
Open

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

shishkin opened this issue Feb 9, 2022 · 2 comments

Comments

@shishkin
Copy link

shishkin commented Feb 9, 2022

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.<anonymous> (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:

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

According to Typescript docs package.json might need explicit "exports" with "types" for the register entry point.

@shishkin
Copy link
Author

shishkin commented Feb 9, 2022

Crossposted to DefinitelyTyped/DefinitelyTyped#58679, since that may be the actual culprit.

@wisko
Copy link

wisko commented Feb 6, 2024

The problem comes from Node being a bit picky with its module resolution, and requires file endings when importing a specific file. This can be solved by adding the appropriate export properties in the package.json, as stated above.

A workaround solution is to include the file ending in your import statement, like this:

import "source-map-support/register.js"

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