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
Regardless of whether or not one of my package's package.json contains "type": "module", Preconstruct always makes "main" point to the CommonJS bundle. However, bundlers generally expect a dependency with "type": "module" to be an ESM package whose package.json "main" points to the ESM build. An ESM package shouldn't have a CommonJS bundle.
Library targets automatically output either native ES modules or CommonJS depending on the target.
main – by default, outputs CommonJS. If the .mjs extension is used, or the "type": "module" field is specified, then an ES module is output instead. module – outputs an ES module. browser – a browser-specific override of the main field. Outputs CommonJS.
I'm running into this issue because one of my packages uses react-markdown which is an ESM dependency, but in my unwanted CommonJS bundle, it's being required.
The following package.json snippet should be invalid:
If you fix this, not only will it make Preconstruct behave correctly, but it will also slash build times for packages with "type": "module" due to CommonJS bundles no longer being built for such packages.
The text was updated successfully, but these errors were encountered:
steve-taylor
changed the title
Preconstruct ignores "type": "module"
Preconstruct ignores "type": "module"Jul 4, 2022
Regardless of whether or not one of my package's package.json contains
"type": "module"
, Preconstruct always makes"main"
point to the CommonJS bundle. However, bundlers generally expect a dependency with"type": "module"
to be an ESM package whose package.json"main"
points to the ESM build. An ESM package shouldn't have a CommonJS bundle.As an example, this is how Parcel works.
I'm running into this issue because one of my packages uses
react-markdown
which is an ESM dependency, but in my unwanted CommonJS bundle, it's beingrequire
d.The following package.json snippet should be invalid:
and should be fixed as
And
should become
Conversely,
should become
as it's not an ESM package.
If you fix this, not only will it make Preconstruct behave correctly, but it will also slash build times for packages with
"type": "module"
due to CommonJS bundles no longer being built for such packages.The text was updated successfully, but these errors were encountered: