Comments (9)
@ErikParso @CoericK started #14 which should resolve this issue. ETA is about 1 or 2 days. Thanks for all the information you provided and for your patience ❤️
As a workaround, you can try enabling TS compilerOptions esModuleInterop
to true
. TypeScript would check whether the module is esModule and either use the value from default
field or just return the module. I was mistakenly thinking that that behavior is configured by allowSyntheticDefaultImports
option 😞
from typings-for-css-modules-loader.
Thanks! esModuleInterop flag with combination of import styles from './styles.css';
helps. Looking forward to fix.
from typings-for-css-modules-loader.
@CoericK have you tried importing it as a default import? eg.
import styles from '../../less/component/logo.less'
Please let me know if it helps to fix the type checking error, I had to change the generated typings a bit to allow using it with style-loader
and without (when people import locals
).
If using default import works if this case, we might somehow consider getting it working for both default imports and * as
.
Edit:
Please double check the order of loaders in your setup - typings-for-css-modules
should come before css-loader
{
test: /\.(less)$/,
use: [
{ loader: 'style-loader' },
{
loader: '@teamsupercell/typings-for-css-modules-loader',
},
{
loader: 'css-loader',
options: { modules: true },
},
{ loader: 'less-loader', options: { sourceMap: true } },
],
}
from typings-for-css-modules-loader.
Hey @DanNSam thanks for your quick answer, I double checked the order and placed @teamsupercell/typings-for-css-modules-loader
before css loader
Also i tried to use the default method
import styles from '../../less/component/logo.less' // undefined
But styles its undefined:
index.tsx?07b1:45 Uncaught TypeError: Cannot read property 'logo' of undefined
from typings-for-css-modules-loader.
@CoericK out of interest, which loader are you using for TypeScript: ts-loader
, awesome-typescript-loader
or babel-loader
?
from typings-for-css-modules-loader.
As I listed on my dependencies I am using ts-loader
{
"@teamsupercell/typings-for-css-modules-loader": "2.0.0",
"css-loader": "3.2.0",
"less-loader": "5.0.0",
"style-loader": "1.0.0",
"ts-loader": "6.1.0",
"typescript": "3.6.3",
"url-loader": "2.1.0",
"webpack": "4.40.2",
"webpack-dev-server": "3.8.0"
}
from typings-for-css-modules-loader.
Hey guys, @DanNSam any updates regarding my issue?
from typings-for-css-modules-loader.
@CoericK it looks like it's a runtime issue after you changed to the default import. I am wondering if your ts-loader
is configured to use your tsconfig.json
- My only idea is that ts-loader
doesn't have a config with allowSyntheticDefaultImports
set 🤷♂
from typings-for-css-modules-loader.
Hello, I have same problem, but with awesome-typescript-loader.
If i use import * as styles from './styles.css';
className={styles.x}
not working due to compilation error 'Property 'x' does not exist on type ...'
className={styles.default.x}
do not work either because default is undefined.
default import import styles from './styles.css';
+ className={styles.x}
not working, again, a default is undefined.
import * as styles from './styles.css';
+ className={(styles as any).x}
is working but i loose strong typing and it doesnt look correct solution to me.
file styles.css.d.ts is generated and looks like this:
export interface IStylesCss {
x: string;
}
export const locals: IStylesCss;
export default locals;
in my webpack.config.js i have:
test: /\.css$/,
use: [
'style-loader',
'@teamsupercell/typings-for-css-modules-loader',
{
loader: "css-loader",
options: {
modules: true,
}
}
]
tsconfig.json:
{
"version": "3.2",
"compileOnSave": true,
"compilerOptions": {
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"module": "commonjs",
"target": "es2015",
"jsx": "react",
"preserveConstEnums": true,
"allowSyntheticDefaultImports": true
}
I didn't even configured sass styles yet.
from typings-for-css-modules-loader.
Related Issues (20)
- Type files not being generated with named/default import HOT 5
- Request to add eslint support for formatter option
- Cannot find module... type declarations.ts HOT 1
- support camelCase HOT 1
- Goto to definition in VScode to the scss file
- Default camelCasing enabled by namedExport in css-loader is throwing error with typings HOT 4
- Expectation for generated typings file HOT 1
- Special chars in CSS Class Names not Stripped from Exports (Causes Error) HOT 3
- [Question] Use with nextjs?
- Support css-loader v5 HOT 4
- Using a dynamic index HOT 1
- Error when importing inside :global HOT 3
- Request to add support for filtering files ends with ".module(s).(css|less|sass)" HOT 1
- ampersand dash syntax does not produce camel case name HOT 1
- Does not work with css-loader 6 + esmodules + namedExport: true HOT 4
- Request to have an option to specify the output directory HOT 1
- Shouldn't create / write to files under node_modules
- Critical vulnerability issue in dependency `loader-utils` version 1.2.3 HOT 6
- Files *.scss.d.ts are not regenerated / updated
- Can I have only camelCased classnames in the generated types?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typings-for-css-modules-loader.