繁体   English   中英

找不到模块“./styles.scss”或其对应的类型声明

[英]Cannot find module './styles.scss' or its corresponding type declarations

我安装

yarn create react-app my-app --template typescript

yarn add sass

应用程序.tsx

import styles from "./styles.scss";

function App() {
  return <div className={styles.App}></div>;
}

export default App;

样式.scss

.App {
  text-align: center;
}

两个文件在同一个文件夹中

当我想导入时,我收到此错误

找不到模块“./styles.scss”或其对应的类型声明

这个问题是因为你在现有的 react-app 上安装了 typescript。

首先在您的项目中放置一个“declarations.d.ts”,并在其中添加以下行代码:

declare module '*.css';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM