Skip to content

ESM Module: ERR_INVALID_PROTOCOL #15374

Closed
@lukaszewczak

Description

@lukaszewczak
  • 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: '' }

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions