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

Switch to JSON module imports #14611

Open
brendankenny opened this issue Dec 14, 2022 · 0 comments
Open

Switch to JSON module imports #14611

brendankenny opened this issue Dec 14, 2022 · 0 comments

Comments

@brendankenny
Copy link
Member

I was looking at https://nodejs.org/api/esm.html#json-modules and noticed there's no mention of --experimental-json-modules anymore, removed in nodejs/node#41736.

I thought it would be a very long process to get there, but import assertions and json modules went stage 3, and since they were already shipping in V8 for some time, the change was mostly just removing code preventing json imports without the flag. That also made backporting the change to 16.15.0 easy, which means all node versions that Lighthouse supports will also support json modules.

Two nice things about this:

  • loading json becomes a regular import (just import pkg from '../package.json' assert {type: 'json'} or pass {assert: {type: 'json'}} into the dynamic import())
  • tsc's resolveJsonModule works with them, so the imported JSON automatically gets types like they had when we were using commonjs

The only tooling change needed is "module": "esnext" in tsconfig-base.json and any json files imported will need to be in the tsconfig include list, and then any json imports should work in node, as well as correctly type check and lint.

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

2 participants