-
Notifications
You must be signed in to change notification settings - Fork 146
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
Error [ERR_INVALID_PROTOCOL]: Protocol 'node:' not supported. Expected 'file:' #904
Comments
I'm running into the same issue :( |
Can confirm this happens as well. |
I am also having the same problem. Using esm to import module that imports builtin Node modules using 'node:*' URL results with an error:
Reproducing:
import ncp from "ncp";
import fs from "node:fs";
import { promisify } from "node:util";
const access = promisify(fs.access);
const copy = promisify(ncp);
async function copyTemplateFiles(options) {
return copy(options.templateDirectory, options.targetDirectory, {
clobber: false,
});
}
export async function createProject(options) {
options = {
...options,
targetDirectory: options.targetDirectory || process.cwd(),
};
const currentFileUrl = import.meta.url;
const templateDir = path.resolve(
new URL(currentFileUrl).pathname,
"../../templates",
options.template.toLowerCase()
);
options.templateDirectory = templateDir;
try {
await access(templateDir, fs.constants.R_OK);
} catch (err) {
console.log("%s Invalid template name", chalk.red.bold("ERROR"));
process.exit(1);
}
console.log("Copy project files");
await copyTemplateFiles(options);
console.log("%s Project ready", chalk.green.bold("DONE"));
return true;
}
import arg from "arg";
import inquirer from "inquirer";
import { createProject } from "./main";
function parseArgumentsIntoOptions(rawArgs) {
const args = arg(
{
"--git": Boolean,
"--test": Boolean,
"--lint": Boolean,
"--yes": Boolean,
"--install": Boolean,
"-g": "--git",
"-t": "--test",
"-l": "--lint",
"-y": "--yes",
"-i": "--install",
},
{
argv: rawArgs.slice(2),
}
);
return {
skipPrompts: args["--yes"] || false,
git: args["--git"] || false,
template: args._[0],
runInstall: args["--install"] || false,
};
}
async function promptForMissingOptions(options) {
const defaultTemplate = "TypeScript";
if (options.skipPrompts) {
return {
...options,
template: options.template || defaultTemplate,
};
}
const questions = [];
if (!options.template) {
questions.push({
type: "list",
name: "template",
message: "Please choose which project template to use",
choices: ["JavaScript", "TypeScript"],
default: defaultTemplate,
});
}
if (!options.git) {
questions.push({
type: "confirm",
name: "git",
message: "Initialize a git repository?",
default: false,
});
}
const answars = await inquirer.prompt(questions);
return {
...options,
template: options.template || answars.template,
git: options.git || answars.git,
};
}
export async function cli(args) {
let options = parseArgumentsIntoOptions(args);
options = await promptForMissingOptions(options);
await createProject(options);
}
{
"dependencies": {
"arg": "^5.0.2",
"chalk": "^4.1.2",
"esm": "^3.2.25",
"inquirer": "^8.0.0",
"ncp": "^2.0.0"
}
}
#!/usr/bin/env node
require = require("esm")(module /*, options*/);
require("../src/cli").cli(process.argv); |
Is there any update related to this issues? And when I use a require, I got this error while using a "sharp" libraries: |
Any latest update for this? |
Problem:
Using
esm
to import module that imports builtin Node modules using'node:*'
URL results with an error: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
:package.json
:index.mjs
:index.cjs
:Running
node index.mjs
gives expected output ("mjs: win32
"), but runningnode index.cjs
results in errorThe text was updated successfully, but these errors were encountered: