From a48a30c8e871038fe1efff8fc2593f05480c068c Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sat, 16 Sep 2023 01:14:37 +0800 Subject: [PATCH 1/3] fix: use ts-node inside the egg-bin deps --- src/middleware/global_options.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/middleware/global_options.ts b/src/middleware/global_options.ts index 26a16d6..6aebbb5 100644 --- a/src/middleware/global_options.ts +++ b/src/middleware/global_options.ts @@ -104,7 +104,7 @@ export default class implements ApplicationLifecycle { } if (pkg.type === 'module') { // use ts-node/esm loader on esm - addNodeOptionsToEnv('--loader ts-node/esm', ctx.env); + addNodeOptionsToEnv(`--loader ${require.resolve('ts-node/esm')}`, ctx.env); } debug('set NODE_OPTIONS: %o', ctx.env.NODE_OPTIONS); From c4d912795eaee0fd5f95b469455ab76a8858331a Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sat, 16 Sep 2023 09:51:12 +0800 Subject: [PATCH 2/3] f --- src/middleware/global_options.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/middleware/global_options.ts b/src/middleware/global_options.ts index 6aebbb5..aa41e34 100644 --- a/src/middleware/global_options.ts +++ b/src/middleware/global_options.ts @@ -104,7 +104,13 @@ export default class implements ApplicationLifecycle { } if (pkg.type === 'module') { // use ts-node/esm loader on esm - addNodeOptionsToEnv(`--loader ${require.resolve('ts-node/esm')}`, ctx.env); + let esmLoader = require.resolve('ts-node/esm'); + if (process.platform === 'win32') { + // ES Module loading with abolute path fails on windows + // https://github.com/nodejs/node/issues/31710#issuecomment-583916239 + esmLoader = `file://${esmLoader}`; + } + addNodeOptionsToEnv(`--loader ${esmLoader}`, ctx.env); } debug('set NODE_OPTIONS: %o', ctx.env.NODE_OPTIONS); From 5d06c773ffb0057e6b0d2bb56d9221247a6b38eb Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sat, 16 Sep 2023 09:54:49 +0800 Subject: [PATCH 3/3] f --- src/middleware/global_options.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/middleware/global_options.ts b/src/middleware/global_options.ts index aa41e34..ed6259a 100644 --- a/src/middleware/global_options.ts +++ b/src/middleware/global_options.ts @@ -1,5 +1,6 @@ import { debuglog } from 'node:util'; import path from 'node:path'; +import { pathToFileURL } from 'node:url'; import { Inject, ApplicationLifecycle, LifecycleHook, LifecycleHookUnit, Program, CommandContext, @@ -108,7 +109,8 @@ export default class implements ApplicationLifecycle { if (process.platform === 'win32') { // ES Module loading with abolute path fails on windows // https://github.com/nodejs/node/issues/31710#issuecomment-583916239 - esmLoader = `file://${esmLoader}`; + // https://nodejs.org/api/url.html#url_url_pathtofileurl_path + esmLoader = pathToFileURL(esmLoader).href; } addNodeOptionsToEnv(`--loader ${esmLoader}`, ctx.env); }