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

--enable-source-maps causes "TypeError [ERR_INVALID_URL]" in esm/resolve #38790

Closed
maxholman opened this issue May 23, 2021 · 5 comments
Closed
Labels
confirmed-bug Issues with confirmed bugs. source maps Issues and PRs related to source map support.

Comments

@maxholman
Copy link

  • Version: v16.2.0
  • Platform: Linux

What steps will reproduce the bug?

// index.js
import { Something } from './something.js';
// something.js
// Empty file, does NOT export `Something`
// package.json
{
  "type": "module"
}

To reproduce:

  • node index.js (throws a SyntaxError, this is expected behavior 👍)
  • node --enable-source-maps index.js (throws TypeError [ERR_INVALID_URL], unexpected behavior 👎)

What is the expected behavior?

$ node index.js

import { Something } from './something.js';
         ^^^^^^^^^
SyntaxError: The requested module './something.js' does not provide an export named 'Something'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:121:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:171:5)
    at async Loader.import (node:internal/modules/esm/loader:178:24)
    at async Object.loadESM (node:internal/process/esm_loader:68:5)

What do you see instead?

$ node --enable-source-maps index.js

TypeError [ERR_INVALID_URL]: Invalid URL
    at __node_internal_captureLargerStackTrace (node:internal/errors:456:5)
    at __node_internal_addCodeToName (node:internal/errors:191:9)
    at new NodeError (node:internal/errors:363:5)
    at onParseError (node:internal/url:537:9)
    at new URL (node:internal/url:613:5)
    at getPackageScopeConfig (node:internal/modules/esm/resolve:177:24)
    at packageResolve (node:internal/modules/esm/resolve:657:25)
    at moduleResolve (node:internal/modules/esm/resolve:739:18)
    at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:853:11)
    at Loader.resolve (node:internal/modules/esm/loader:89:40)
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:137:31)
    at async ModuleJob.run (node:internal/modules/esm/module_job:171:5)
    at async Loader.import (node:internal/modules/esm/loader:178:24)
    at async Object.loadESM (node:internal/process/esm_loader:68:5) {
  input: './package.json',
  code: 'ERR_INVALID_URL'

Additional information

A cursory review tracked this to ModuleJob._instantiate in esm/module_job.js.

The code seems to expect a full path as the first element in the array, but when --enable-source-maps is on, the stack does not have this path.

As a result, the full error message is passed down into esm/resolve instead of a pathname, resulting in an Invalid URL.

@aduh95 aduh95 added confirmed-bug Issues with confirmed bugs. source maps Issues and PRs related to source map support. labels May 23, 2021
@aduh95
Copy link
Contributor

aduh95 commented May 24, 2021

Ping @bcoe

@bcoe
Copy link
Contributor

bcoe commented Jun 8, 2021

@aduh95 @maxholman acknowledged, although I'm unlikely to have any time to dig into this bug for at least a week.

bcoe added a commit to bcoe/node-1 that referenced this issue Jun 12, 2021
Logic in module_job.js assumes detailed stack trace from node_errors.cc
which is not populated when --enable-source-maps is set.

Fixes nodejs#38790
bcoe added a commit to bcoe/node-1 that referenced this issue Jun 25, 2021
Logic in module_job.js assumes detailed stack trace from node_errors.cc
which is not populated when --enable-source-maps is set.

Fixes nodejs#38790
targos pushed a commit that referenced this issue Jul 11, 2021
Logic in module_job.js assumes detailed stack trace from node_errors.cc
which is not populated when --enable-source-maps is set.

Fixes #38790

PR-URL: #39017
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
@saostad
Copy link

saostad commented Jul 12, 2021

Hi, I am getting this error message.
I see this issue has closed so when I can expect the fix?

input: './package.json',
  code: 'ERR_INVALID_URL'

to fix removed --enable-source-maps flag.

@bcoe
Copy link
Contributor

bcoe commented Jul 12, 2021

@saostad could you provide a snippet of code that causes this error?

targos pushed a commit that referenced this issue Sep 4, 2021
Logic in module_job.js assumes detailed stack trace from node_errors.cc
which is not populated when --enable-source-maps is set.

Fixes #38790

PR-URL: #39017
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
@christopher-caldwell
Copy link

christopher-caldwell commented Aug 3, 2022

Having this issue as well on 16.0.0. Here's the command: node --enable-source-maps --experimental-specifier-resolution=node ./build/index.js. There isn't much more I can think of to provide, this command just doesn't work without removing the source maps flag.

Edit:
Fixed by using version 16.14.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. source maps Issues and PRs related to source map support.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants