【问题标题】:CSS modules not working in Codesandbox - can't find files even though they existCSS 模块在 Codesandbox 中不起作用 - 即使它们存在也找不到文件
【发布时间】:2020-11-29 04:43:59
【问题描述】:

我正在尝试构建一个项目,我只是将我的代码从 VSCode 移动到 Codesandbox。我必须提到该代码在 VSC 中运行良好,但由于某种原因它在 Codesandbox 中无法运行 - 找不到 CSS 模块。我想我可能在我的设置中遗漏了一些东西,因为我查看了其他示例并且代码似乎相同(导入)。获取所有文件的错误是:

Cannot find module './Example.module.css' or its corresponding type declarations.

完整的代码在这里:

https://codesandbox.io/s/burger-builder-project-173uw?file=/src/Components/Layout/Layout.tsx

有谁知道可能出了什么问题?谢谢。

【问题讨论】:

标签: javascript reactjs typescript codesandbox


【解决方案1】:

我找到了解决此问题的一种方法(这就是我使用 CSS 文件的方式):

// Layout.tsx

import React from "react";
import BurgerBuilder from "../../ContainerBurgerBuilder";

// CSS
import "./Layout.module.css";

然后在你的render 方法中:

render() {
   return (
      <div className="Content">
         <BurgerBuilder/>
      </div>

   );
}

【讨论】:

  • 我的代码,令人惊讶的是,似乎工作,我只是无法摆脱错误。您的解决方案破坏了整个应用程序。谢谢。
  • 很遗憾听到这个消息。希望您能尽快找到更合适的解决方案。
【解决方案2】:

在您的 html 文件中启用 javascript,然后我认为它会起作用

【讨论】:

  • 这是一条评论。
猜你喜欢
  • 2019-07-26
  • 1970-01-01
  • 2018-12-21
  • 2021-08-24
  • 1970-01-01
  • 2020-04-10
  • 2023-01-28
  • 1970-01-01
  • 2014-09-08
相关资源
最近更新 更多