-
-
Notifications
You must be signed in to change notification settings - Fork 534
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
ESM fix for node 14.13.1 breaking change #1130
Comments
Maybe |
If anyone needs a quick fix (as the linked PR has not been released on npm), experimentally this solution seems to work by early deferring Node.js builtin modules (i.e. Create a new file import url from "url";
// initialize ts-node ESM loader; promise to early initialize
const esmLoader = new Promise(async (resolve, reject) => {
try {
resolve(await import("ts-node/esm.mjs"));
} catch (error) {
reject(error);
}
});
// delegate to ts-node ESM loader
export async function resolve(specifier, context, defaultResolve) {
// resolves change from 'nodejs:' to 'node:'
if (url.parse(specifier).protocol === null) return defaultResolve(...arguments);
return (await esmLoader).resolve(...arguments);
}
export async function getFormat() {
return (await esmLoader).getFormat(...arguments);
}
export async function transformSource() {
return (await esmLoader).transformSource(...arguments);
} |
Over the weekend I merged a fix to master, so this should already be fixed
on master.
…On Thu, Nov 5, 2020, 1:46 AM concision ***@***.***> wrote:
If anyone needs a quick fix, experimentally this solution seems to work by
early deferring Node.js builtin modules (i.e. null specifier). Might not
work in 100% of scenarios - your mileage may vary.
Create a new file ts-node-esm-fix.mjs and set the ESM loader to it (e.g.
--loader=./ts-node-fix.mjs):
import url from "url";
// initialize ts-node ESM loader; promise to early initializeconst esmLoader = new Promise(async (resolve, reject) => {
try {
resolve(await import("ts-node/esm.mjs"));
} catch (error) {
reject(error);
}});
// delegate to ts-node ESM loaderexport async function resolve(specifier, context, defaultResolve) {
// resolves change from 'nodejs:' to 'node:'
if (url.parse(specifier).protocol === null) return defaultResolve(...arguments);
return (await esmLoader).resolve(...arguments);}export async function getFormat() {
return (await esmLoader).getFormat(...arguments);}export async function transformSource() {
return (await esmLoader).transformSource(...arguments);}
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#1130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35OGETJA6EP2BB2Q4V7DSOJC4TANCNFSM4SL67DRA>
.
|
Npm can install ts-node directly from github instead of npmjs.com, allowing you to use the latest code from master. |
Ah, I did not realize that npm/yarn will build a module directly from GitHub! Thanks for letting me know! And thank you for your work on ts-node! :) |
Pretty sure it's cuz the URL protocol for native modules changed from
nodejs:
tonode:
and has to do with our necessary forking of node's resolver.Fix must:
nodejs:
; after needs to usenode:
Relevant conversation starts here: #1007 (comment)
The text was updated successfully, but these errors were encountered: