Amb*_*ier 3 sass typescript css-modules gatsby
我正在尝试让 typescript 和 sass 模块在 Gatsby 项目中协同工作。
我正在使用gatsby-plugin-ts-loader
和gatsby-plugin-sass
插件。
索引.tsx
import * as React from 'react';
import styles from './index.module.scss'; // TS2307: Cannot find module './index.module.scss'.
export default () => <div className={styles.root}>
<h1>Hello Gatsby!</h1>
</div>;
Run Code Online (Sandbox Code Playgroud)
索引.模块.scss
.root {
h1 {
color: red;
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误TS2307: Cannot find module './index.module.scss'.
。如果我把它放在@ts-ignore
scss 导入行之前,我会得到TypeError: index_module_scss_1.default is undefined
.
"esModuleInterop": true
tsconfig.json
src/global.d.ts
:// necessary to make scss module work. See https://github.com/gatsbyjs/gatsby/issues/8144#issuecomment-438206866
declare module '*.scss' {
const content: {[className: string]: string};
export = content;
}
Run Code Online (Sandbox Code Playgroud)
import styles from './index.module.scss';
.root
和root
;)。来源https://github.com/gatsbyjs/gatsby/issues/8144#issuecomment-438206866
归档时间: |
|
查看次数: |
2741 次 |
最近记录: |