【发布时间】:2021-03-11 06:43:04
【问题描述】:
我使用 Emotion 在我的项目中制作样式组件,现在它给我带来了问题。我是这样安装的:
npm i @emotion/react @emotion/styled gatsby-plugin-emotion
例如,如果我想在 Header 组件中使用它,我会这样做:
import React from 'react';
import { Link } from 'gatsby';
import Navegacion from './navegacion';
import { jsx, css } from '@emotion/react';
const Header = () => {
return (
<header
css={css`
background-color: #0d283b;
padding: 1rem;
`}
>
<div
css={css`
max-width: 120rem;
margin: 0 auto;
text-align: center;
@media (min-width: 768px) {
display: flex;
align-items: center;
justify-content: space-between;
}
`}
>
<Link>Bienes Raíces</Link>
<Navegacion />
</div>
</header>
)
}
export default Header;
但是当我运行 gatsby develop 时,它给了我这个错误
`WebpackError: The `@emotion/core` package has been renamed to `@emotion/react`. Please import it like this `import { jsx } from '@emotion/react'.
有人可以帮助我吗?
我的 package.json 文件
"dependencies": {
"@emotion/core": "^11.0.0",
"@emotion/react": "^11.1.1",
"@emotion/styled": "^11.0.0",
"gatsby": "^2.26.1",
"gatsby-image": "^2.5.0",
"gatsby-plugin-emotion": "^4.5.0",
"gatsby-plugin-manifest": "^2.6.1",
"gatsby-plugin-offline": "^3.4.0",
"gatsby-plugin-react-helmet": "^3.4.0",
"gatsby-plugin-sharp": "^2.8.0",
"gatsby-source-filesystem": "^2.5.0",
"gatsby-transformer-sharp": "^2.6.0",
"prop-types": "^15.7.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-helmet": "^6.1.0"
},
还有我的 gatsby-config 文件:
module.exports = {
siteMetadata: {
title: `Gatsby Default Starter`,
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
author: `@gatsbyjs`,
},
plugins: [
`gatsby-plugin-emotion`,
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
// {
// resolve: `gatsby-plugin-manifest`,
// options: {
// name: `gatsby-starter-default`,
// short_name: `starter`,
// start_url: `/`,
// background_color: `#663399`,
// theme_color: `#663399`,
// display: `minimal-ui`,
// icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
// },
// },
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
// `gatsby-plugin-offline`,
],
}
【问题讨论】:
标签: css reactjs gatsby styled-components emotion