Skip to content

Commit

Permalink
fix: use fileurl on import
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Dec 25, 2024
1 parent eebc2f6 commit 4917ce9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eggjs/bin",
"version": "7.0.0-beta.0",
"version": "7.0.0-beta.2",
"publishConfig": {
"access": "public"
},
Expand Down Expand Up @@ -80,7 +80,7 @@
"typescript": "5"
},
"scripts": {
"postinstall": "node scripts/postinstall.mjs",
"postinstall-skip": "node scripts/postinstall.mjs",
"lint": "eslint --cache src test --ext .ts",
"pretest": "npm run clean && npm run lint -- --fix && npm run prepublishOnly",
"test": "npm run test-local",
Expand Down
14 changes: 7 additions & 7 deletions src/middleware/global_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ export default class GlobalOptions implements ApplicationLifecycle {
findPaths.unshift(ctx.args.base);
}
ctx.args.tscompiler = tscompiler ?? 'ts-node/register';
const tsNodeRegister = importResolve(ctx.args.tscompiler, {
let tsNodeRegister = importResolve(ctx.args.tscompiler, {
paths: findPaths,
});
// should require tsNodeRegister on current process, let it can require *.ts files
// e.g.: dev command will execute egg loader to find configs and plugins
// await importModule(tsNodeRegister);
// let child process auto require ts-node too
if (isESM) {
tsNodeRegister = pathToFileURL(tsNodeRegister).href;
addNodeOptionsToEnv(`--import ${tsNodeRegister}`, ctx.env);
} else {
addNodeOptionsToEnv(`--require ${tsNodeRegister}`, ctx.env);
Expand All @@ -127,12 +128,11 @@ export default class GlobalOptions implements ApplicationLifecycle {
let esmLoader = importResolve('ts-node/esm', {
paths: [ getSourceDirname() ],
});
if (process.platform === 'win32') {
// ES Module loading with absolute path fails on windows
// https://github.com/nodejs/node/issues/31710#issuecomment-583916239
// https://nodejs.org/api/url.html#url_url_pathtofileurl_path
esmLoader = pathToFileURL(esmLoader).href;
}
// ES Module loading with absolute path fails on windows
// https://github.com/nodejs/node/issues/31710#issuecomment-583916239
// https://nodejs.org/api/url.html#url_url_pathtofileurl_path
// Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
esmLoader = pathToFileURL(esmLoader).href;
// wait for https://github.com/nodejs/node/issues/40940
addNodeOptionsToEnv('--no-warnings', ctx.env);
addNodeOptionsToEnv(`--loader ${esmLoader}`, ctx.env);
Expand Down

0 comments on commit 4917ce9

Please sign in to comment.