I am unable to import scss file in below format.
import * as styles from './index.scss';
getting below error :
can not find module './index.scss'
I want to use class name like below :
className={styles.anyClassName}
I am unable to import scss file in below format.
import * as styles from './index.scss';
getting below error :
can not find module './index.scss'
I want to use class name like below :
className={styles.anyClassName}
In order to import SCSS as object in TS like this :
import * as styles from './index.scss';
declare module '*.scss' {
const content: {[className: string]: string};
export = content;
}
https://basarat.gitbooks.io/typescript/docs/types/ambient/d.ts.html
I came across this question recently, and figured it might be useful to add an answer that helps do this at the time the project is generated (using create-react-app) and without the need to eject or modify the webpack configs:
create-react-app my-app --scripts-version=react-scripts-scss-ts
One of this way you work with .scss style on your create-react-app project. you need some steps on your projects.
yarn run eject from your project command prompt.config/webpack.config.dev.js approximately line #173. Replace test: /\.css$/, with test: /\.s?css$/, config/webpack.config.prod.js approximately line #185. Replace test: /\.css$/, with test: /\.s?css$/,add your .scss file on your component like
import './App.scss';
and uses like
<div className="your-styled-class-name">
<p>Styed Text</p>
</div>
That's it.
create-react-app command then follow this answer. stackoverflow.com/questions/49856468/…I solved that issue using Run Powershell as Administrator and execute that code: Set-ExecutionPolicy RemoteSigned Press A And Enter
Refer this if not clear: After npm updating packages .ps1 cannot be loaded because running scripts is disabled on this system
and refer this alsp: No such file or directory