vadimdemedes / pastel

🎨 Next.js-like framework for CLIs made with Ink
https://term.ink/pastel
MIT License
2.18k stars 36 forks source link

Resolve "ERR_UNSUPPORTED_ESM_URL_SCHEME" Error in Windows #55

Closed Railly closed 1 year ago

Railly commented 1 year ago

Hi there First off, thank you for your amazing work, I really enjoy how you approach and adjust the CLI paradigm like Next.js.

Now I've encountered an issue on Windows where Node.js's ESM loader throws an ERR_UNSUPPORTED_ESM_URL_SCHEME error when trying to dynamically import a module using an absolute path.

This line of code in read-commands.js is causing the issue:

const m = (await import(filePath));

By using pathToFileUrl from node:url worked for me, this should ensure compatibility with Windows without affecting other OS.

import { pathToFileURL } from 'node:url';
...
const filePath = path.join(directory, file);
const fileURL = pathToFileURL(filePath);
const m = (await import(fileURL));

Note: Could you please confirm if you will be working on that? If not, I can contribute effortlessly.

vadimdemedes commented 1 year ago

Thank you, I'd appreciate a PR ;)

AugusDogus commented 1 year ago

Just so you're aware @vadimdemedes, it appears that the version uploaded to the npm registry does not have this fix, although the version on Github releases does have it.

This is to say that npm install pastel@latest does grab v2.0.1, but it is still broken on Windows. Navigating to the node_modules/ folder confirms that the same line in read-commands.js is still there and it is not using node:url.

vadimdemedes commented 1 year ago

@AugusDogus Damn, I forgot the prepare script, so code wasn't recompiled when publishing. Thanks for reporting, pushing a patch right now.

vadimdemedes commented 1 year ago

@AugusDogus Published a 2.0.2.