frenic / csstype

Strict TypeScript and Flow types for style based on MDN data
MIT License
1.7k stars 69 forks source link

Unable to resolve path to module w/ eslint: import/no-unresolved #113

Closed gregveres closed 3 years ago

gregveres commented 3 years ago

We recently changed our eslint rules to include import/no-unresolved Now I get an error on import * as CSS from 'csstype';

I get unable to resolve path to module.

I have seen the other issues where the solution is to ensure that tsconfig.ts: compilerOptions.moduleResolution = 'node' and that is what mine is set to.

Any suggestions?

frenic commented 3 years ago

I'm not sure. Never heard of this before. Maybe because Typescript provides similar errors. But I think this issue should be raised at ESLint.

gregveres commented 3 years ago

You are probably right. BTW, I converted the index.d.ts into a standard ts file and things work better. I had to rearrange things because you output things in alphabetical order rather than in use order, but after that everything works great.

jonlepage commented 3 years ago

Am starting work with CSS and i get same issue , i try many way ! Any tips ? image my jsconfig.json

{
    "compilerOptions": {
        "target": "es2015",
        "module": "es2015",
        "jsx": "react",
        "checkJs": true,
        "lib": ["esnext", "dom"],
        "moduleResolution": "node",

        "allowSyntheticDefaultImports": true

    },
    "include": ["src/**/*"]
}
frenic commented 3 years ago

@djmisterjon That seems to be a type error thought?

jonlepage commented 3 years ago

i found a workaround with import directly in jsdoc.

but i'm a bit idiot 🥇 , i just found out that React already has all types for css with CSSProperties['key'] ! So those thing work both, sorry for the inconvenience.

    * @param {import('csstype').Property.FlexDirection} [props.FlexDirection] - Using Import() with csstype
    * @param {React.CSSProperties['flexDirection']} [props.FlexDirection] - Using arrayKey with React

all fine thanks

paztis commented 3 years ago

the problem is the field "main" in the package.json is empty eslint-plugin-import tries to resolve the main field and fails.

You need to provide a index.js file, even if this one is empty. IN fact you need to provide the index.d.ts and the index.js produced by the typescript compilation