Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Error [ERR_INVALID_PROTOCOL]: Protocol 'node:' not supported. Expected 'file:' #904

@msipinski

Description

@msipinski

Problem:

Using esm to import module that imports builtin Node modules using 'node:*' URL results with an error:

file:///C:/NodeJsProjects/esm-error-test/some-external-module.mjs:1
Error [ERR_INVALID_PROTOCOL]: Protocol 'node:' not supported. Expected 'file:'
    at file:///C:/NodeJsProjects/esm-error-test/some-external-module.mjs:1
    at Generator.next (<anonymous>)

Import with 'node:*' type URL lies inside external package so I can't replace it. Switching my project from CJS to ESM is probably not possible (I'm creating Electron.js app).

Reproducing:

some-external-module.mjs:

import process from 'node:process'

export default process.platform

package.json:

{
  "dependencies": {
    "esm": "^3.2.25"
  }
}

index.mjs:

import platform from './some-external-module.mjs'

console.log('mjs: ' + platform)

index.cjs:

require = require('esm')(module)
const platform = require('./some-external-module.mjs')

console.log('cjs: ' + platform)

Running node index.mjs gives expected output ("mjs: win32"), but running node index.cjs results in error

  • esm version: 3.2.25
  • node version: v14.15.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions