You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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:
import pkg from '../package.json' assert {type: 'json'}
or pass{assert: {type: 'json'}}
into the dynamicimport()
)resolveJsonModule
works with them, so the imported JSON automatically gets types like they had when we were using commonjsThe only tooling change needed is
"module": "esnext"
intsconfig-base.json
and any json files imported will need to be in the tsconfiginclude
list, and then any json imports should work in node, as well as correctly type check and lint.The text was updated successfully, but these errors were encountered: