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

ESM Module: ERR_INVALID_PROTOCOL #15374

Closed
lukaszewczak opened this issue Sep 12, 2017 · 6 comments
Closed

ESM Module: ERR_INVALID_PROTOCOL #15374

lukaszewczak opened this issue Sep 12, 2017 · 6 comments
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. windows Issues and PRs related to the Windows platform.

Comments

@lukaszewczak
Copy link
Contributor

lukaszewczak commented Sep 12, 2017

  • Version: v8.5.0
  • Platform: Windows 64-bit
  • Subsystem: Es module

Hi,

First of all, I want to thank you for your wonderful work!

I try to run simple example using es module (which @MylesBorins share on Twitter), but I stuck on error.

At first I updated today to node version 8.5.0. and write this two simple files

helper.mjs

export function helperMethod() {
    console.log(`I'm helping!`);
}

index.mjs

import {helperMethod} from './helper.mjs';

helperMethod();

and after running command node --experimental-modules index.mjs, I receive error

F:\Projekty\Learn\nodejs-workshop>node --experimental-modules index.mjs
(node:7036) ExperimentalWarning: The ESM module loader is experimental.
{ AssertionError [ERR_ASSERTION]: An invalid error message key was used: ERR_INVALID_PROTOCOL.
    at message (internal/errors.js:70:3)
    at NodeError (internal/errors.js:29:13)
    at resolveRequestUrl (internal/loader/resolveRequestUrl.js:84:11)
    at Loader.import (internal/loader/Loader.js:61:27)
    at Function.Module._load (module.js:462:27)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:201:16)
    at bootstrap_node.js:626:3
  generatedMessage: false,
  name: 'AssertionError [ERR_ASSERTION]',
  code: 'ERR_ASSERTION',
  actual: undefined,
  expected: true,
  operator: '==' }

Additionally it looks like some problem with NodeErorr module.

I updated node source code and build it locally to test this behavior, and then I receive this error when I try to run this two files

F:\Projekty\Learn\node>cd Release

F:\Projekty\Learn\node\Release>node -e "console.log('Hello from Node.js', process.version)"
Hello from Node.js v9.0.0-pre

F:\Projekty\Learn\node\Release>node --experimental-modules index.mjs
(node:18136) ExperimentalWarning: The ESM module loader is experimental.
{ Error [ERR_INVALID_PROTOCOL]: Protocol "f:" not supported. Expected "file:"
    at resolveRequestUrl (internal/loader/resolveRequestUrl.js:84:11)
    at Loader.import (internal/loader/Loader.js:61:27)
    at Function.Module._load (module.js:438:27)
    at Function.Module.runMain (module.js:641:10)
    at startup (bootstrap_node.js:201:16)
    at bootstrap_node.js:626:3 [Symbol(code)]: 'ERR_INVALID_PROTOCOL' }

And this how specifier, baseUrl and url object looks like in resolveRequestURl.js module, after I put some console.log.

resolveRequestURl.js

  const baseURL = normalizeBaseURL(baseURLOrString);
  console.log(`log: ${specifier}, ${baseURL}`);
  let url = search(specifier, baseURL);
  console.log(url);

  if (url.protocol !== 'file:') {
    throw new errors.Error('ERR_INVALID_PROTOCOL', url.protocol, 'file:');
  }

result

log: F:\Projekty\Learn\node\Release\index.mjs, file:///F:/Projekty/Learn/node/Release/
URL {
  href: 'f:\\Projekty\\Learn\\node\\Release\\index.mjs',
  origin: 'null',
  protocol: 'f:',
  username: '',
  password: '',
  host: '',
  hostname: '',
  port: '',
  pathname: '\\Projekty\\Learn\\node\\Release\\index.mjs',
  search: '',
  searchParams: URLSearchParams {},
  hash: '' }
@beardedtim
Copy link

Is this related to this issue?

@mscdex mscdex added the esm Issues and PRs related to the ECMAScript Modules implementation. label Sep 12, 2017
@Arnavion
Copy link

Arnavion commented Sep 13, 2017

Linux:

> const { resolve } = process.binding('module_wrap'); resolve('/home/arnavion/main.mjs', 'file:///home/')

URL {
  href: 'file:///home/arnavion/main.mjs',
  origin: 'null',
  protocol: 'file:',
  username: '',
  password: '',
  host: '',
  hostname: '',
  port: '',
  pathname: '/home/arnavion/main.mjs',
  search: '',
  searchParams: URLSearchParams {},
  hash: '' }

Windows:

> const { resolve } = process.binding('module_wrap'); resolve('C:\\main.mjs', 'file://c/')

URL {
  href: 'c:\\main.mjs',
  origin: 'null',
  protocol: 'c:',
  username: '',
  password: '',
  host: '',
  hostname: '',
  port: '',
  pathname: '\\main.mjs',
  search: '',
  searchParams: URLSearchParams {},
  hash: '' }

Perhaps the code thinks the leading C: is a URL protocol so doesn't convert it to a file: URL.

@addaleax addaleax added the windows Issues and PRs related to the Windows platform. label Sep 13, 2017
MylesBorins added a commit to MylesBorins/node that referenced this issue Sep 13, 2017
This error code originally landed in a semver-major commit and is used
by the ESM implementation. This backport includes the error message
and the documentation for the error.

I did attempt to write a test for this, but it did not seem possible
to catch an exception during import, I was also unable to execute
`node --experimental-modules` properly inside of a child_process.

I'll dig more into getting a test together, but we should backport
this fix in the mean time.

Refs: nodejs#14423
Fixes: nodejs#15374
guybedford added a commit to guybedford/node that referenced this issue Sep 13, 2017
@jdalton
Copy link
Member

jdalton commented Sep 14, 2017

PR at #15389.

MylesBorins added a commit that referenced this issue Sep 14, 2017
This error code originally landed in a semver-major commit and is used
by the ESM implementation. This backport includes the error message
and the documentation for the error.

I did attempt to write a test for this, but it did not seem possible
to catch an exception during import, I was also unable to execute
`node --experimental-modules` properly inside of a child_process.

I'll dig more into getting a test together, but we should backport
this fix in the mean time.

Refs: #14423
Fixes: #15374
MylesBorins added a commit that referenced this issue Sep 14, 2017
This error code originally landed in a semver-major commit and is used
by the ESM implementation. This backport includes the error message
and the documentation for the error.

I did attempt to write a test for this, but it did not seem possible
to catch an exception during import, I was also unable to execute
`node --experimental-modules` properly inside of a child_process.

I'll dig more into getting a test together, but we should backport
this fix in the mean time.

Refs: #14423
Fixes: #15374

PR-URL: #15388
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@XHMM
Copy link

XHMM commented Sep 16, 2017

Hi, I still encoutered this error.The following is my test :
node v8.5.0
npm v5.4.2


add.mjs

export function add(a,b) {
  return a+b;
}

test.mjs

import {add} from './add.mjs'
console.log(add(1,2));

run node --experimental-modules test.mjs

output

(node:16016) ExperimentalWarning: The ESM module loader is experimental.
{ AssertionError [ERR_ASSERTION]: An invalid error message key was used: ERR_INVALID_PROTOCOL.
    at message (internal/errors.js:70:3)
    at NodeError (internal/errors.js:29:13)
    at resolveRequestUrl (internal/loader/resolveRequestUrl.js:84:11)
    at Loader.import (internal/loader/Loader.js:61:27)
    at Function.Module._load (module.js:462:27)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:201:16)
    at bootstrap_node.js:626:3
  generatedMessage: false,
  name: 'AssertionError [ERR_ASSERTION]',
  code: 'ERR_ASSERTION',
  actual: undefined,
  expected: true,
  operator: '==' }


I am confused , can someone tell me the reason ? Thanks in addvanced.

@amitport
Copy link

@XHMM, 8.5.0 has this issue. You need to wait for a new release.

@XHMM
Copy link

XHMM commented Sep 16, 2017

@amitport Thanks for reminding , I just thought this has been fixed .

addaleax pushed a commit to addaleax/ayo that referenced this issue Sep 17, 2017
Fixes: nodejs/node#15374
PR-URL: nodejs/node#15389
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
jasnell pushed a commit that referenced this issue Sep 20, 2017
Fixes: #15374
PR-URL: #15389
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Qard pushed a commit to Qard/ayo that referenced this issue Sep 21, 2017
Fixes: nodejs/node#15374
PR-URL: nodejs/node#15389
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

8 participants