Having modules: { namedExport: ... } inside the webpack.config.js unset.
Given import styles from "./styles.scss" the value of styles.cardContainer is the content of cardContainer class from the scss file.
Given import { cardContainer } from "./styles.scss" the value of cardContainer is undefined, or an exception is thrown.
Having modules: { namedExport: ... } inside the webpack.config.js set to true.
Given import styles from "./styles.scss" the value of styles.cardContainer is the content of cardContainer class from the scss file.
Given import { cardContainer } from "./styles.scss" the value of cardContainer is the content of cardContainer class from the scss file.
Having modules: { namedExport: ... } inside the webpack.config.js unset.
Given import styles from "./styles.scss" the value of styles.cardContainer is the content of cardContainer class from the scss file.
Given import { cardContainer } from "./styles.scss" the value of cardContainer is the content of cardContainer class from the scss file. Typescript error Module '"*.scss"' has no exported member 'cardContainer' is being thrown. Code still works with the use of //@ts-ignore.
Having modules: { namedExport: ... } inside the webpack.config.js set to true.
Given import styles from "./styles.scss" the value of styles.cardContainer is undefined. The value of styles is an empty object.
Given import { cardContainer } from "./styles.scss" the value of cardContainer is undefined. Typescript error Module '"*.scss"' has no exported member 'cardContainer' is being thrown.
// webpack.config.js
// using the extension .module.scss or .module.sass
{
test: sassModuleRegex,
use: getStyleLoaders(
{
esModule: true,
importLoaders: 3,
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
modules: {
getLocalIdent: getCSSModuleLocalIdent,
namedExport: true
},
},
'sass-loader'
),
// index.tsx
import { cardContainer } from "./styles.scss";
console.log(cardContainer);
config/webpack.config.jssrc/CardContainerSass/index.tsxsrc/CardContainerSass/CardSass/index.tsxyarn && yarn startWhen you have a problem with CRA please prefer to use CRA repo for issues.
Solutions:
style-loader, mini-css-extract-plugin and css-loader to the latest versions, v1 of style-loader and v4 for css-loader have bugs with named exports, you can read it in CHANGELOG isEnvDevelopment && {
loader: require.resolve('style-loader'),
options: {
modules: {
namedExport: true
}
}
},
for style-loader (same for mini-css-extract-plugin, in near future we will release the new version and you will not need to do this extra setup)
import on named in src/CardContainerSass.tsx and src/CardContainerSass/CardSass/index.tsxtypescript-plugin-css-modules just not working, please ask about it in typescript-plugin-css-modulesAlso you don't need CaseSensitivePathsPlugin with "forceConsistentCasingInFileNames": true,, it just doesn't make sense, current configuration is not good, you need change it or wait CRA update
But you can use as workaround:
declare module '*.scss' {
const classes: { [key: string]: string };
export classes;
}
Feel free to feedback, unfortunately I can't fix ts problem here
Thank you for your response! :) I didn't know that those versions had bugs
However, after upgrading dependencies, I'm just getting more errors (XD), which I assume is due to a huge load of outdated webpack plugins mangled together inside the webpack.config.js file produced after ejecting CRA.
I'll just go ahead and drop this project and start anew setting babel, webpack etc. by hand
You can update deps steps by steps, should be no problems, firstly update loades, then plugins, then other tools
Most helpful comment
When you have a problem with
CRAplease prefer to useCRArepo for issues.Solutions:
style-loader,mini-css-extract-pluginandcss-loaderto the latest versions, v1 of style-loader and v4 for css-loader have bugs with named exports, you can read it in CHANGELOGfor
style-loader(same formini-css-extract-plugin, in near future we will release the new version and you will not need to do this extra setup)importon named insrc/CardContainerSass.tsxandsrc/CardContainerSass/CardSass/index.tsxtypescript-plugin-css-modulesjust not working, please ask about it intypescript-plugin-css-modulesAlso you don't need
CaseSensitivePathsPluginwith"forceConsistentCasingInFileNames": true,, it just doesn't make sense, current configuration is not good, you need change it or wait CRA update