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
We hope to make this enabled by default, without requiring a flag, in a future version of Node (potentially as soon as Node 22 in April 2024). This will mean that any Node app and dependency without a package.jsontype field will have a slower startup time. Therefore we would appreciate any help that npm can provide in ensuring that both application developers and library authors add a type field to every package.json file, even if it’s just making explicit the default "type": "commonjs". I agree with @benjamingr’s suggested improvements above.
npm/rfcs#620 is already open, which suggests one of these changes. Perhaps now that this performance penalty to type-less packages is potentially coming to Node, it might be timely to act on that proposal?
We can get this into the init-package-json roadmap but there is no way to edit any already published package so the vast majority of packages in the ecosystem just got slower load times.
More specifically, packages that don't currently include a type field or use .mjs/.cjs get slightly lower load times. Which is many of them, for sure; but all they need to do is add "type": "commonjs" and the penalty disappears. Yes this doesn't help unmaintained packages or transitive dependencies of old packages, etc, but that's the trade-off we've chosen.
Activity
wraithgar commentedon Oct 2, 2023
This is best discussed in https://github.com/npm/rfcs
GeoffreyBooth commentedon Nov 17, 2023
@wraithgar This landed in Node and was released in 21.1.0:
We hope to make this enabled by default, without requiring a flag, in a future version of Node (potentially as soon as Node 22 in April 2024). This will mean that any Node app and dependency without a
package.jsontypefield will have a slower startup time. Therefore we would appreciate any help thatnpmcan provide in ensuring that both application developers and library authors add atypefield to everypackage.jsonfile, even if it’s just making explicit the default"type": "commonjs". I agree with @benjamingr’s suggested improvements above.npm/rfcs#620 is already open, which suggests one of these changes. Perhaps now that this performance penalty to
type-less packages is potentially coming to Node, it might be timely to act on that proposal?wraithgar commentedon Nov 17, 2023
We can get this into the
init-package-jsonroadmap but there is no way to edit any already published package so the vast majority of packages in the ecosystem just got slower load times.GeoffreyBooth commentedon Nov 17, 2023
More specifically, packages that don't currently include a
typefield or use.mjs/.cjsget slightly lower load times. Which is many of them, for sure; but all they need to do is add"type": "commonjs"and the penalty disappears. Yes this doesn't help unmaintained packages or transitive dependencies of old packages, etc, but that's the trade-off we've chosen.ljharb commentedon Nov 17, 2023
… which is the vast majority of packages, for the foreseeable future.
GeoffreyBooth commentedon Nov 22, 2023
@wraithgar FYI this has been backported and released in Node 20.10.0: https://nodejs.org/en/blog/release/v20.10.0