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

Migrate node.js to ES6 modules #861

Open
jonathanolson opened this issue Feb 6, 2020 · 9 comments
Open

Migrate node.js to ES6 modules #861

jonathanolson opened this issue Feb 6, 2020 · 9 comments

Comments

@jonathanolson
Copy link
Contributor

We should investigate what is possible. Node 8.9.0 I think added support under an experimental flag, and Node 13+ looks like it includes it by default, so we may need to bump our node.js version for supporting this.

Entry from the planning doc:

(MP, MK, ??? hours) [post-publication] Migrate chipper/perennial or other non-sim repos? What about phet-io wrappers?
MP: I could look into the build-server after the initial project is complete. The code navigation benefits seems like a worthwhile improvement.
MK: phet-io-wrapper architecture will need to support running in IE, but that doesn’t mean some of our wrapper suite like studio can’t be updated.
SR: See https://nodejs.org/api/esm.html for documentation about using import/export in Node (This may be experimental)

@mattpen
Copy link
Contributor

mattpen commented Feb 6, 2020

Both of our servers (bayes and phet-server) are using node v10.16.3. This is the previous LTS (current LTS is 12). I've tested ES6 imports with the flag and they work as long as files are named with the mjs extension.

@chrisklus
Copy link
Contributor

@zepumph @samreid @chrisklus think this would be good to discuss in developer meeting a couple weeks after the migration.

@mattpen
Copy link
Contributor

mattpen commented May 28, 2020

Deferred till october when Node 14 can be installed on production servers.

@ariel-phet
Copy link
Contributor

Calendar reminder added

@samreid
Copy link
Member

samreid commented Nov 7, 2020

On Thursday, @zepumph and I volunteered to investigate converting to this pattern in our Node code, partly so that the 2-3 files which are used as preloads and require modules can be simplified as modules. I'll probably investigate this within the next few days.

@samreid
Copy link
Member

samreid commented Nov 7, 2020

I identified a potential roadblock--we invoke chipper code via grunt which is defined using require statements and module.exports. For example, adding "type": "module" to package.json, then in chipper/Gruntfile.js, changing to:

import X from '../chipper/js/grunt/Gruntfile.js';
export default X;

then running grunt from chipper/ yields this problem:

~/apache-document-root/main/chipper$ grunt
Loading "Gruntfile.js" tasks...ERROR
>> Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/samreid/apache-document-root/main/chipper/Gruntfile.js
>> require() of ES modules is not supported.
>> require() of /Users/samreid/apache-document-root/main/chipper/Gruntfile.js from /Users/samreid/apache-document-root/main/chipper/node_modules/grunt/lib/grunt/task.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
>> Instead rename Gruntfile.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/samreid/apache-document-root/main/chipper/package.json.
Warning: Task "default" not found. Use --force to continue.

Aborted due to warnings.

Does grunt prevent us from using ES6 modules?

@samreid samreid removed their assignment Nov 7, 2020
@jonathanolson
Copy link
Contributor Author

Does grunt prevent us from using ES6 modules?

What happens when we try converting the top-level Gruntfile.js to use import?

@chrisklus
Copy link
Contributor

From 11/12/20 dev meeting:

We like the sound of not needing grunt in the future, but we're not sure if this issue is a good enough reason to get rid of it.

@zepumph volunteered to continue investigation here.

@chrisklus chrisklus reopened this Nov 12, 2020
@zepumph
Copy link
Member

zepumph commented Mar 5, 2021

PhET-iO wrappers will be handled over in https://github.com/phetsims/phet-io-wrappers/issues/399. Renaming this issue to just handle Node code on the project.

@zepumph zepumph changed the title Migrate node.js or wrapper code to ES6 modules Migrate node.js to ES6 modules Mar 5, 2021
@zepumph zepumph removed their assignment Mar 3, 2023
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