我正在尝试将 .scss 文件导入到 .tsx 打字稿文件中。
但是我收到以下错误。当我跑npm run tsc
src/public/app1/index.tsx:5:20 - 错误 TS2307:找不到模块“./index.scss”。
5 从“./index.scss”导入样式;~~~~~~~~~~~~~~~
发现 1 个错误。
索引.tsx
import React from "react";
import { render } from "react-dom";
import App from "./App";
import styles from "./index.scss";
render(
<App/>,
document.getElementById("root"),
);
Run Code Online (Sandbox Code Playgroud)
索引.scss
body {
background:red;
color: #005CC5;
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
我看到一个解决方案是在我的项目的根目录中创建一个 decleration.d.ts 文件。但这对我没有用。无法导入 CSS/SCSS 模块。TypeScript 说“找不到模块”
declaration.d.ts
declare module '*.scss';
Run Code Online (Sandbox Code Playgroud)
配置文件
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es6", /* …Run Code Online (Sandbox Code Playgroud)