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

ERR_MODULE_NOT_FOUND, --es-module-specifier-resolution=node not working in v19.0.0 #45108

Closed
n8sabes opened this issue Oct 21, 2022 · 1 comment

Comments

@n8sabes
Copy link

n8sabes commented Oct 21, 2022

Version

19.0.0

Platform

Darwin Kernel Version 21.6.0

Subsystem

No response

What steps will reproduce the bug?

A project that is built with modules fails to execute. Configuration:

package.json:

{
    ...
    "type": "module",
    "scripts": {
        "start": "tsc && node --es-module-specifier-resolution=node ./dist/index.js"
    }
    ...
}

tsconfig.json:

{
    "compilerOptions": {
        "target": "ES2022",
        "module": "ES2022",
        "lib": [
            "ES2022"
        ]
      ...
    }
    ...
}

index.ts:

import logger from "./utils/logger"; // Note there is no extension, thus the use of --es-module-specifier-resolution=node

How often does it reproduce? Is there a required condition?

Every execution

What is the expected behavior?

Works in v18.x

What do you see instead?

After upgrading to v19.0.0 the execution environment reports the following error:

node:internal/errors:484
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/fubar/helloworld/dist/utils/logger' imported from /Users/fubar/helloworld/dist/index.js
    at new NodeError (node:internal/errors:393:5)
    at finalizeResolution (node:internal/modules/esm/resolve:257:11)
    at moduleResolve (node:internal/modules/esm/resolve:850:10)
    at defaultResolve (node:internal/modules/esm/resolve:1058:11)
    at nextResolve (node:internal/modules/esm/loader:161:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:829:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:412:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Additional information

No response

@aduh95
Copy link
Contributor

aduh95 commented Oct 21, 2022

It's mentioned in the CHANGELOG: https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V19.md#other-notable-changes

You need to use --experimental-loader flag to achieve the same result, see https://github.com/nodejs/loaders-test/tree/main/commonjs-extension-resolution-loader for an example.

Closing because it is not a bug, but feel free to continue the discussion or ask more questions.

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