Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

javascript - Why does @chakra-ui/gatsby-plugin crashes gatsby?

Trying to apply ChakraUI to my gatsby project.

I've installed all the necessary packages

"@chakra-ui/gatsby-plugin": "^1.0.1"

"@chakra-ui/react": "^1.1.3"

"@emotion/react": "^11.1.4"

"@emotion/styled": "^11.0.0"

"framer-motion": "^3.2.0"

then added the plugin to gatsby-config.js

...
{
  resolve: '@chakra-ui/gatsby-plugin',
  options: {
    isResettingCSS: true,
    isUsingColorMode: true,
  },
},
...

but after I run `yarn develop, the output is:

  

> yarn develop
yarn run v1.22.10
$ gatsby develop
success open and validate gatsby-configs - 0.045s
success load plugins - 0.693s
success onPreInit - 0.039s
success initialize cache - 0.018s
success copy gatsby files - 0.093s
success onPreBootstrap - 0.022s
success createSchemaCustomization - 0.010s
success Checking for changed pages - 0.001s
success source and transform nodes - 0.068s
success building schema - 0.234s
info Total nodes: 31, SitePage nodes: 1 (use --verbose for breakdown)
success createPages - 0.004s
success Checking for changed pages - 0.001s
success createPagesStatefully - 0.123s
success update schema - 0.031s
success write out redirect data - 0.002s
success Build manifest and related icons - 0.126s
success onPostBootstrap - 0.139s
info bootstrap finished - 5.753s
success onPreExtractQueries - 0.003s
success extract queries from components - 0.207s
success write out requires - 0.010s
success run page queries - 0.029s - 3/3 104.13/s

 ERROR 

There was an error compiling the html.js component for the development server.
See our docs page on debugging HTML builds for help https://gatsby.dev/debug-html TypeError: Object(...) is not a
function


  27 |   };
  28 | 
> 29 |   return transform ? compose(transform, rtlTransform) : rtlTransform;
     |                             ^
  30 | }
  31 | 
  32 | export function logical(opts) {


  WebpackError: TypeError: Object(...) is not a function
  
  - logical-prop.js:29 
    node_modules/@chakra-ui/styled-system/dist/esm/utils/logical-prop.js:29:29
  
  - logical-prop.js:41 
    node_modules/@chakra-ui/styled-system/dist/esm/utils/logical-prop.js:41:1
  
  - position.js:20 
    node_modules/@chakra-ui/styled-system/dist/esm/config/position.js:20:22
  
  - index.js:1 
    node_modules/@chakra-ui/styled-system/dist/esm/config/index.js:1:1
  
  - index.js:1 
    node_modules/@chakra-ui/styled-system/dist/esm/index.js:1:1
  
  - index.js:1 
    node_modules/@chakra-ui/system/dist/esm/index.js:1:1
  
  - chakra-provider.js:1 
    node_modules/@chakra-ui/react/dist/esm/chakra-provider.js:1:1
  
  - index.js:1 
    node_modules/@chakra-ui/react/dist/esm/index.js:1:1
  
  - gatsby-ssr.js:1 
    node_modules/@chakra-ui/gatsby-plugin/gatsby-ssr.js:1:1
  

not finished Building development bundle - 5.148s

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
  

Do you have any ideas what to do? I don't even use custom html.js.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Watch out, @chakra-ui/gatsby-plugin is not the same as gatsby-plugin-chakra-ui. Follow this example: https://www.gatsbyjs.com/plugins/gatsby-plugin-chakra-ui/

You'll need to install these packages:

yarn add gatsby-plugin-chakra-ui @chakra-ui/core @emotion/core @emotion/styled emotion-theming

In your gatsby-config.js:

module.exports = {
  plugins: ["gatsby-plugin-chakra-ui"],
};

Once installed, use it as you wish. For example:

import React from "react";
import { Box, Text } from "@chakra-ui/core";

function IndexPage() {
  return (
    <Box p={8}>
      <Text fontSize="xl">Hello World</Text>
    </Box>
  );
}

export default IndexPage;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.6k users

...