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

Rename binary that supports ESM to node2 #42469

Closed
Raynos opened this issue Mar 25, 2022 · 10 comments · May be fixed by #49407
Closed

Rename binary that supports ESM to node2 #42469

Raynos opened this issue Mar 25, 2022 · 10 comments · May be fixed by #49407
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. feature request Issues that request new features to be added to Node.js. stale

Comments

@Raynos
Copy link
Contributor

Raynos commented Mar 25, 2022

What is the problem this feature will solve?

I'm currently using nodejs with require and commonjs,

I cannot require an .js file that uses ESM and it's a terrible user experience.

What is the feature you are proposing to solve the problem?

Can we remove ESM support from node and make a node2 binary that supports ESM ?

What alternatives have you considered?

Add the ability to require an ESM module.

@Raynos Raynos added the feature request Issues that request new features to be added to Node.js. label Mar 25, 2022
@aduh95
Copy link
Contributor

aduh95 commented Mar 26, 2022

I'm not sure I understand the ask, even if we remove support for ESM and/or add a node2 binary, you still wouldn't be able to require an ESM file 🤔

@jasnell
Copy link
Member

jasnell commented Mar 26, 2022

If I understand the ask, it's for ./node to only ever work with commonjs and for ./node2 to only ever work with ESM. It's a python2/python3 type split. If that is indeed the ask, strong -1.

@VoltrexKeyva VoltrexKeyva added the esm Issues and PRs related to the ECMAScript Modules implementation. label Mar 26, 2022
@bnb
Copy link
Contributor

bnb commented Mar 27, 2022

It's a python2/python3 type split.

also strong -1 on this.

@benjamingr
Copy link
Member

Is there an issue with passing a CLI flag to the node binary or adding a package.json with "type": "module"?

@Raynos
Copy link
Contributor Author

Raynos commented Mar 28, 2022

I'm building an application to run AWS style lambdas locally with support for multiple languages.

When the user specifies their python file they choose python2 or python3.

When the user specifies their nodejs javascript file they specify node12 / 14 / 16 etc. I then try to execute said nodejs file as a commonjs file by using require() .

My customer is confused their nodejs file written in ESM does not work with my application, this is because ESM is a breaking change and they should have been forced to choose node or node2 to decide whether they want me to load a commonjs or esm program for local exection and AWS Lambda emulation.

Alternatively, if I can require an ESM file then that would also not be a breaking change.

@devsnek
Copy link
Member

devsnek commented Mar 28, 2022

cpython (which is what I assume you're referring to) releases aren't named python2 or python3, that's done by distro packaging people (although by python foundation recommendation), and they do that because of backward compat (modifying old python scripts to use python2 in the interpreter directive). the esm problem is sort of the inverse of that, so I'm not sure how much sense the approach makes.

@RaisinTen
Copy link
Contributor

When the user specifies their nodejs javascript file they specify node12 / 14 / 16 etc. I then try to execute said nodejs file as a commonjs file by using require() .

You could modify the input format to allow users to encode the module type and run the js file accordingly.

@aduh95
Copy link
Contributor

aduh95 commented Mar 28, 2022

When the user specifies their nodejs javascript file they specify node12 / 14 / 16 etc. I then try to execute said nodejs file as a commonjs file by using require() .

You could modify the input format to allow users to encode the module type and run the js file accordingly.

Alternatively you could use import(pathToFileURL(pathToTheUserFile)), import() let's you load both CJS and ESM files. (Note that the file in question should use .cjs / .mjs extensions for this to work in all cases)

@github-actions
Copy link
Contributor

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label Sep 25, 2022
@github-actions
Copy link
Contributor

There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

For more information on how the project manages feature requests, please consult the feature request management document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. feature request Issues that request new features to be added to Node.js. stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants