Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when importing from ESM auto entrypoint #422

Merged
merged 2 commits into from
Mar 6, 2024

Conversation

aduth
Copy link
Member

@aduth aduth commented Mar 6, 2024

🛠 Summary of changes

Fixes an error which occurs when trying to load the auto entrypoint in a bundler which resolves ESM imports.

Module not found: Error: Can't resolve './components' in '/node_modules/@18f/identity-design-system/build/esm'

This is an identical issue as what was addressed in #400, but the earlier pull request only addressed the instance of the issue within index.js. This pull request applies the same fix to auto.js.

This issue was surfaced as part of ongoing work in 18F/identity-dashboard#748

📜 Testing Plan

Verify included test passes:

  1. make build
  2. node --test test/imports.test.js

Optionally, verify in an external project that you can reference /auto:

  1. In identity-design-system, ensure everything is built: make build
  2. In external project, modify package.json version for @18f/identity-design-system to point to file:../identity-design-system (assumes identity-design-system is checked out to the parent folder)
  3. In external project's JavaScript entrypoint that references the @18f/identity-design-system, import as: import '@18f/identity-design-system/auto';
  4. Verify you have no errors when building JavaScript

@aduth aduth requested a review from Sgtpluck March 6, 2024 16:44
Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, neat test!

@aduth
Copy link
Member Author

aduth commented Mar 6, 2024

LGTM, neat test!

Yeah unfortunately it seems like TypeScript isn't taking nicely to the types in the happy-dom package 🙈 So might have to find another way to stub the DOM.

aduth added 2 commits March 6, 2024 16:33
happy-dom has some issues in their typings unrelated to what's used in our project

Per documentation, this also "can save time during compilation at the expense of type-system accuracy"

See: https://www.typescriptlang.org/tsconfig#skipLibCheck
@aduth aduth force-pushed the aduth-import-auto-error branch from 234cf02 to b13d216 Compare March 6, 2024 21:34
@aduth
Copy link
Member Author

aduth commented Mar 6, 2024

LGTM, neat test!

Yeah unfortunately it seems like TypeScript isn't taking nicely to the types in the happy-dom package 🙈 So might have to find another way to stub the DOM.

Found a nice solution to this in b13d216. More detail in the commit message.

Bonus is that it might make TypeScript check a bit faster! (..."at the expense of type-system accuracy" 🙉 )

@aduth aduth merged commit 362a4d3 into main Mar 6, 2024
4 checks passed
@aduth aduth deleted the aduth-import-auto-error branch March 6, 2024 21:45
@aduth aduth mentioned this pull request Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants