How to use Chakra UI?
See original GitHub issueI would like to use Chakra UI with my react-static application. I created a new react-static app and followed the instructions at:
https://chakra-ui.com/docs/getting-started
I installed the dependencies:
yarn add @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^4
Then I added the ChakraProvider to index.tsx:
const render = (Comp: Function) => {
renderMethod(
<ChakraProvider>
<AppContainer>
<Comp />
</AppContainer>
</ChakraProvider>,
target
)
}
When building I got the error:
Running plugins...
[❌] Application bundling failed
/home/ldlework/src/ldlework-static/node_modules/framer-motion/dist/es/components/AnimateSharedLayout/utils/batcher.js 35:28-41
"export '__spreadArray' was not found in 'tslib'
@ /home/ldlework/src/ldlework-static/node_modules/framer-motion/dist/es/index.js
@ /home/ldlework/src/ldlework-static/node_modules/@chakra-ui/transition/dist/esm/collapse.js
@ /home/ldlework/src/ldlework-static/node_modules/@chakra-ui/transition/dist/esm/index.js
@ /home/ldlework/src/ldlework-static/node_modules/@chakra-ui/react/dist/esm/index.js
@ /home/ldlework/src/ldlework-static/src/index.tsx
@ multi react-hot-loader/patch ../lib/bootstrapPlugins.js ../lib/bootstrapTemplates.js /home/ldlework/src/ldlework-static/src/index.tsx
/home/ldlework/src/ldlework-static/node_modules/framer-motion/dist/es/components/AnimateSharedLayout/utils/batcher.js 35:42-55
"export '__spreadArray' was not found in 'tslib'
@ /home/ldlework/src/ldlework-static/node_modules/framer-motion/dist/es/index.js
@ /home/ldlework/src/ldlework-static/node_modules/@chakra-ui/transition/dist/esm/collapse.js
@ /home/ldlework/src/ldlework-static/node_modules/@chakra-ui/transition/dist/esm/index.js
@ /home/ldlework/src/ldlework-static/node_modules/@chakra-ui/react/dist/esm/index.js
@ /home/ldlework/src/ldlework-static/src/index.tsx
@ multi react-hot-loader/patch ../lib/bootstrapPlugins.js ../lib/bootstrapTemplates.js /home/ldlework/src/ldlework-static/src/index.tsx
/home/ldlework/src/ldlework-static/node_modules/framer-motion/dist/es/render/index.js 280:21-34
In googling, I found this error was due to old TS lib, so I updated both typescript and tslib:
yarn add -D typescript@4.2.4
yarn add tslib@2.2.0
This allowed the site to build but at runtime in the browser I get:
Uncaught SyntaxError: Unexpected token '['
at eval (<anonymous>)
at ES6ProxyComponentFactory (react-hot-loader.development.js:341)
at createClassProxy (react-hot-loader.development.js:814)
at updateProxyById (react-hot-loader.development.js:1301)
at Object.register (react-hot-loader.development.js:2849)
at register (motion.js:84)
at Module.../../framer-motion/dist/es/index.js (motion.js:86)
at __webpack_require__ (bootstrap:789)
at fn (bootstrap:100)
at Module.../../@chakra-ui/transition/dist/esm/index.js (index.js:44)
How can Chakra UI be made to work with react-static? Any guidance is appreciated.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Chakra UI - A simple, modular and accessible component ...
Chakra UI is a simple, modular and accessible component library that gives you the building blocks you need to build your React applications....
Read more >Create React App - Chakra UI
Create React App allows users to create a project using a template, which determines the files and dependencies included with the generated project....
Read more >Installing and Using Chakra UI with React | Pluralsight
To install chakra-ui , run the following command in your project's root directory. ... Chakra UI uses Emotion for handling component styles. As ......
Read more >How to Use Chakra UI with Next.js and React - freeCodeCamp
Step 0: Creating a new React project with Next.js · Step 1: Installing and configuring Chakra UI in Next.js · Step 2: Adding...
Read more >Chakra UI: Sleek UI Components for React - KnowledgeHut
Chakra UI is a modern component library for React. It comes with a set of reusable and composable React components that you may...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I got a fresh typescript
react-static create
with Chakra UI running and wanted to post my steps here for posterity. FWIW, I didn’t encounter the error the original poster described.Steps to reproduce:
react-static create
(choose typescript)yarn add @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^6
framer-motion
here differs from earlier posts, but this is what is currently noted in chakra ui’s docsAdd
ChakraProvider
toApp.tsx
:Add
node.api.js
filenpm: start
got the following error for various differentframer-motion
exports:node.api.js
file at root:At that point, it bundled without errors and Chakra UI example components I added worked in the browser without any console errors.
Hope this is useful!
Alright. So same issue as original poster. This error is a better error tho.
I don’t know if Chakra UI is compatible with SSR. It doesn’t use SSR in debug, but does in production/build. Here it’s trying to SSR and that fails. Perhaps @RodrigoPrior has more information.