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

Remove ESM Node support mention from the installation doc #19830

Closed
TomasHubelbauer opened this issue Jul 11, 2020 · 14 comments
Closed

Remove ESM Node support mention from the installation doc #19830

TomasHubelbauer opened this issue Jul 11, 2020 · 14 comments

Comments

@TomasHubelbauer
Copy link

Citing from https://threejs.org/docs/#manual/en/introduction/Installation:

Second, Node.js support for ES modules is ... complicated. As of Node.js v12, the core library can be imported as a CommonJS module, with require('three'). However, most example components in examples/jsm cannot. Future versions of Node.js may resolve this, but in the meantime you may need to use workarounds like esm to enable your Node.js application to recognize ES modules.

As of latest Node (14.5.0 at the time of writing), ESM support in Node works as expected and nothing special is required (like using CLI flags or MJS extension). Therefore I would like to discuss whether it's appropriate to remove this section of the document.

If it is deemed so, I'll be happy to send in a PR removing it or rewording it.

@cecilemuller
Copy link
Contributor

Perhaps a good time would be once 14 becomes LTS (in October I think) ?

@TomasHubelbauer
Copy link
Author

Yeah, that makes sense. I'll ping this issue when it does.

@donmccurdy
Copy link
Collaborator

It might also be necessary to use older versions of node until headless-gl has a prebuilt binary for v14. Building it from source has been iffy for me, and a WebGL alternative is important for three.js.

@looeee
Copy link
Collaborator

looeee commented Jul 12, 2020

People are likely to be using Node v12 for at least another few years, judging from previous Node releases.

We could change the paragraph:

Support for modules in older versions of Node is... complicated. If you're using Node v14 or higher, you should have no problems. However, for Node.js v12 and below, while the core library can be imported as a CommonJS module using require('three'), most example components in examples/jsm cannot. For these, you may need to use workarounds like esm to enable ES modules in your Node.js application.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 27, 2020

As of latest Node (14.5.0 at the time of writing), ESM support in Node works as expected and nothing special is required (like using CLI flags or MJS extension).

Sorry for asking but you say nothing special is required. I have just upgrade to node v14.6.0 and if I now try to execute one of the three.js converter scripts (e.g. obj2three) via:

node utils/converters/obj2three.js examples/models/obj/emerald.obj

I still get:

Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

It works if I modify the package.json. But it appears it does not "just work".

@TomasHubelbauer
Copy link
Author

@Mugen87 I think (but I might be wrong) that that's expected - that it is a Node thing. Similarly to how in browser JavaScript when you want to use ESM, you need to use <script type="module">. I am not aware of any plans on the Node's side to make the module package type the default (and I don't think it would happen without it also happening on the browser side which I find even more unlikely as it would be a big breaking change).

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 28, 2020

Okay, thanks for the clarification. I think the documentation should reflect this since many users (especially beginners) will do the same (naive) thing I did^^. So it should at least mention that it's required to configure package.json in order to run ES6 module based scripts like above.

@TomasHubelbauer
Copy link
Author

It's true, I will patch this PR to include this when I have a chance.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 28, 2020

I think this is an issue, not a PR 😇 .

@TomasHubelbauer
Copy link
Author

Oh yeah, sorry, I have an associated PR for this somewhere.

@donmccurdy
Copy link
Collaborator

Related: #18498

@mrdoob
Copy link
Owner

mrdoob commented Jul 29, 2020

I guess this can be closed then?

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 29, 2020

TBH, I don't feel strong about this. I suggested #19830 (comment) but one could also argue that it's not the task of the three.js documentation to explain how to use ES6 modules with node.

@Mugen87
Copy link
Collaborator

Mugen87 commented Aug 19, 2020

Closing for now.

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

No branches or pull requests

6 participants