GithubHelp home page GithubHelp logo

Comments (9)

Obi-Dann avatar Obi-Dann commented on June 1, 2024 2

@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.

ErikParso avatar ErikParso commented on June 1, 2024 2

Thanks! esModuleInterop flag with combination of import styles from './styles.css'; helps. Looking forward to fix.

from typings-for-css-modules-loader.

Obi-Dann avatar Obi-Dann commented on June 1, 2024

@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.

CoericK avatar CoericK commented on June 1, 2024

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.

Obi-Dann avatar Obi-Dann commented on June 1, 2024

@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.

CoericK avatar CoericK commented on June 1, 2024

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.

CoericK avatar CoericK commented on June 1, 2024

Hey guys, @DanNSam any updates regarding my issue?

from typings-for-css-modules-loader.

Obi-Dann avatar Obi-Dann commented on June 1, 2024

@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.

ErikParso avatar ErikParso commented on June 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.