小编Ril*_*ook的帖子

带有 PostCSS 8 的 Gatsby - 尝试导入错误:“component.module.css”不包含默认导出(作为“样式”导入)

我有一个基于入门项目的 Gatsby and Sanity 站点。到目前为止,一切都运行良好,但我今天在 package.json 文件中更新了所有包和插件,以消除所有 npm 警告。这包括更新到 Gatsby 3.0.3 和 PostCss 8(我现在也在使用 gatsby-plugin-postcss 4.0.0)。

我设法解决了一些初始错误,但现在我遇到了一个问题,它无法识别我的 CSS 模块。我收到每个组件文件的错误:

尝试导入错误:“[componentName].module.css”不包含默认导出(作为“样式”导入)

当我在反应组件中导入 css 文件时

import styles from './[componentName].module.css'
Run Code Online (Sandbox Code Playgroud)

样式对象返回未定义。我是否需要降级到其中一些软件包的旧版本?

这是我的 package.json:

  "dependencies": {
    "@cloudflare/wrangler": "^1.15.0",
    "@fontsource/montserrat": "^4.2.2",
    "@fontsource/raleway": "^4.2.2",
    "@sanity/block-content-to-react": "^2.0.7",
    "@sanity/client": "^2.2.6",
    "@sanity/image-url": "^0.140.22",
    "date-fns": "^2.19.0",
    "dotenv": "^8.2.0",
    "gatsby": "^3.0.3",
    "gatsby-plugin-anchor-links": "^1.2.1",
    "gatsby-plugin-manifest": "^3.0.0",
    "gatsby-plugin-react-helmet": "^4.0.0",
    "gatsby-source-sanity": "^6.0.5",
    "get-youtube-id": "^1.0.1",
    "postcss-import": "^14.0.0",
    "postcss-preset-env": "^6.7.0",
    "react": "^17.0.1",
    "react-autosize-textarea": "^7.1.0",
    "react-dom": "^17.0.1",
    "react-helmet": "^6.1.0",
    "react-hook-form": "^6.15.4",
    "react-icons": "^4.2.0",
    "react-script": "^2.0.5",
    "react-youtube": "^7.13.1" …
Run Code Online (Sandbox Code Playgroud)

webpack postcss css-modules gatsby netlify

4
推荐指数
1
解决办法
1204
查看次数

标签 统计

css-modules ×1

gatsby ×1

netlify ×1

postcss ×1

webpack ×1