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
{{ message }}
Repository navigation
A package.json lacking a "type" field is not treated as if it contained "type": "commonjs" #30245
When I execute $ node --experimental-modules ./sub1/foo.js in the root folder, it results in an error Error [ERR_REQUIRE_ESM]: Must use import to load ES Module, while $ node --experimental-modules ./sub2/foo.js does not throw any error.
Therefore, the document is incorrect and it is likely non-top-level "type" fields in package.json file affects whether the JS files are treated as ES modules or CommonJS modules.
changed the title [-]Top-level "type" field of package.json file does not default to "commonjs"[/-][+]A package.json lacking a "type" field is not treated as if it contained "type": "commonjs"[/+]on Nov 4, 2019
Thanks for the really clear bug report here and for testing this edge case. You are exactly right about the expectations here. I've posted a fix for this in #30256.
Activity
[-]Top-level "type" field of package.json file does not default to "commonjs"[/-][+]A package.json lacking a "type" field is not treated as if it contained "type": "commonjs"[/+]guybedford commentedon Nov 5, 2019
Thanks for the really clear bug report here and for testing this edge case. You are exactly right about the expectations here. I've posted a fix for this in #30256.
module: fix for empty object in InternalModuleReadJSON
module: fix for empty object in InternalModuleReadJSON
module: fix for empty object in InternalModuleReadJSON