Skip to content
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

Test REPL in nodenext type=module projects; may need a tweak to ensure REPL is CJS #1752

Open
cspotcode opened this issue May 17, 2022 · 4 comments
Milestone

Comments

@cspotcode
Copy link
Collaborator

cspotcode commented May 17, 2022

While working on #1694, stumbled upon a possible REPL issue:
if package.json type = module, and you fire up the REPL, how is the REPL being compiled? Should make sure it's treated as CJS.

Should also check ts-node -pe "is this code ESM or CJS? What should it be?"

@cspotcode
Copy link
Collaborator Author

The fix here might be as simple as either:

A) naming the repl's "virtual file" to end in the .cts file extension
B) using the moduleTypes option internally to override the repl file to be CJS.

Internally, the repl is a virtual .ts file that exists solely in memory. This allows us to typecheck it like any other file. Since it already has a name, we can give it the cts file extension and get the same benefits.

If we go the cts route, we will need to be sure this works even without module=nodenext. We will also need to confirm which TSC versions support cts. It may be acceptable to use cts when the user's TSC version is new enough, and gracefully fallback to legacy repl behavior otherwise. Users with ESM projects are likely already on a new TS version, so we solve the problem for most users who would encounter it.

@thetutlage
Copy link
Contributor

thetutlage commented Nov 7, 2022

Not sure, if I understand the solution correctly. But, if you are recommending to always used CommonJS, then shouldn't that be wrong?

If my project is in ESM, then the REPL should be ESM too?

@cspotcode
Copy link
Collaborator Author

The question is: what does node's REPL do? We'll match that.

@GabenGar
Copy link

REPL doesn't support ESM:
nodejs/node#33369

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants