Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🛠 Summary of changes
Fixes another regression of #395, where downstream projects can resolve the CommonJS built output, but would treat its code as ES Modules, since the project's top-level
package.json
includes"type": "module"
. It's unclear why this wouldn't have been an issue prior to #395.Example failure: 18F/identity-idp#9992
Error:
I'm not 100% about the solution here since typically a package would only contain a single, root-level
package.json
. However, I've tested to confirm that it works, and have seen the idea referenced in a few places:The alternatives could be to use either Babel CLI's (prior to 9.0.0)
--out-file-extension .cjs
or ESBuild's (after 9.0.0)--out-extension:.js=.cjs
to control the file extension output for CommonJS. However, there's not an easy solution to change the source code's path references based on the built output type, aside from using a third-party plugin likebabel-plugin-replace-import-extension
.📜 Testing Plan
This is easiest to verify via the pull request mentioned above: 18F/identity-idp#9992
cd identity-idp
git checkout dependabot/npm_and_yarn/18f/identity-design-system-8.1.1
yarn install
yarn mocha app/javascript/packages/clipboard-button/clipboard-button-element.spec.ts
echo '{"type":"commonjs"}' > node_modules/@18f/identity-design-system/build/cjs/package.json
yarn mocha app/javascript/packages/clipboard-button/clipboard-button-element.spec.ts