shoelace: Create React App doesn't work out of the box with Shoelace
UPDATE: The original issue mentioned below has been resolved, but a new issue was uncovered regarding Create React App + Shoelace. See below for more details.
View original issue
Describe the bug
After updating to 2.0.0-beta.86, getting import error (probably due to recent package.json exports field changes, using vite 3.2.5).
Importing like this:
import { SlButton } from "@shoelace-style/shoelace/dist/react";
Produces this error:
Internal server error: Missing "./dist/react" export in "@shoelace-style/shoelace" package
This can be fixed by changing the import to this:
import { SlButton } from "@shoelace-style/shoelace/dist/react/index.js";
Possible solutions
- Update documentation to use the ā@shoelace-style/shoelace/dist/react/index.jsā import
- Might be able to maintain current behaviour by modifying the package.json exports field to add this:
{
"./dist/react": "./dist/react/index.js",
}
- Could output a
./dist/react.jsfile, add that to the exports and import using@shoelace-style/shoelace/dist/react.js
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 21 (16 by maintainers)
Commits related to this issue
- Add useDefineForClassFields false to tsconfig per Issue #1049 — committed to BasyaLipman/shoelace by deleted user 2 years ago
Thanks, everyone. I just tried from scratch and it seems to be working fine with 2.0.0-beta.87. I also decided to make a video showing how to setup a CRA with Shoelace.
https://www.youtube.com/watch?v=Ku2mJCJgvLs
Iām going to close this since it seems to be resolved now. If anyone is still having an issue with this, please make sure youāre using 2.0.0-beta.87 and report back if the problem persists for you!
The CRA issue described with errors about needing: ā@babel/plugin-transform-classesā seems unrelated to the package.json exports changes. I installed
@shoelace-style/shoelace2.0.0-beta.83 (version before the exports changes) in a newly created CRA project and get the same error.Now havenāt touched create-react-app in a while, but was able to get the error to go away in CRA in two ways (not sure Iād recommend either approach though):
1. Customising babel with ācracoā
Was able to get it working using https://craco.js.org/ to customise the babel config, roughly this:
adjust package.json scripts to use craco:
Create a
craco.config.jsfile with this:2. Changing ābrowserslistā in package.json
After reading this: https://github.com/facebook/create-react-app/issues/11339#issuecomment-907813993
changing the browserslist in package.json to just ālast 1 chrome versionā, it seems to work in development at least:
So it seems CRA configures itās babel settings depending on the specified browser support, and the out-of-the-box settings are configuring it in a way that doesnāt like shoelace.
Havenāt done much testing beyond this⦠but yea it would probably be good if shoelace worked out of the box in CRA as itās probably still pretty popular (despite in my opinion, better alternatives like viteās react preset etc). Not sure what needs changed though to make it work.
@ajmchambers - I was having this issue.
Just installed shoelace in a sample Create React App today - am new to react and shoelace, so this may be totally unrelated.
I implemented your first solution, and now I am getting: