Skip to content

PostCSS types not included; TypeError #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MynockSpit opened this issue Dec 20, 2021 · 13 comments · Fixed by #147
Closed

PostCSS types not included; TypeError #146

MynockSpit opened this issue Dec 20, 2021 · 13 comments · Fixed by #147

Comments

@MynockSpit
Copy link

Bug report

When using css-minimizer-webpack-plugin with npm 7.7.6 and Typescript, the cssnano/node_modules/postcss is not being installed. As a result, builds fail on this type error.

Actual Behavior


node_modules/css-minimizer-webpack-plugin/types/utils.d.ts:9:30 - error TS2307: Cannot find module 'cssnano/node_modules/postcss' or its corresponding type declarations.

9 export type CssNano = import("cssnano/node_modules/postcss").Plugin<
                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error.

Expected Behavior

I know I'm not supposed to say "it should work", but, uh. It looks like you're pulling a type from somewhere that is unreliable. From what I can tell, it's possibly be the result of @types/cssnano being a direct dependency in your package (and getting it's deps installed), but being a transitive dependency when it's being used. Not sure. What I do know for certain is that in my project that's using css-minimizer-webpack-plugin, the @types/cssnano folder looks like this:

Screen Shot 2021-12-20 at 2 34 06 PM

When you pull down css-minimizer-webpack-plugin directly, it looks like this:

Screen Shot 2021-12-20 at 2 37 36 PM

How Do We Reproduce?

Using css-minimizer-webpack-plugin in a Typescript project should trigger this.

Please paste the results of npx webpack-cli info here, and mention other relevant information

forge [get-css-smaller-nh] $ npx webpack-cli info

  System:
    OS: macOS 11.6.1
    CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
    Memory: 1.35 GB / 32.00 GB
  Binaries:
    Node: 15.14.0 - ~/.nvm/versions/node/v15.14.0/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.7.6 - ~/.nvm/versions/node/v15.14.0/bin/npm
  Browsers:
    Chrome: 96.0.4664.110
    Firefox: 91.4.0
    Safari: 15.2
  Packages:
    css-loader: ^6.2.0 => 6.5.1
    css-minimizer-webpack-plugin: ^3.1.4 => 3.3.0
    csv-loader: ^3.0.3 => 3.0.3
    filemanager-webpack-plugin: ^6.1.4 => 6.1.7
    html-webpack-plugin: ^5.3.2 => 5.5.0
    style-loader: ^3.2.1 => 3.3.1
    ts-loader: ^9.2.3 => 9.2.6
    webpack: ^5.45.1 => 5.65.0
    webpack-bundle-analyzer: ^4.5.0 => 4.5.0
    webpack-cli: ^4.7.2 => 4.9.1
    webpack-dev-server: ^3.11.2 => 3.11.3
    xml-loader: ^1.2.1 => 1.2.1

I suspect that if you change the type to point at postcss instead of cssnano/node_modules/postcss that this error will go away, but you may need to add @types/postcss to your dependencies.

@alexander-akait
Copy link
Member

Postcss has own types, we don't need to install @types/postcss, check it out https://github.com/postcss/postcss/tree/main/lib, run npm ls postcss

@alexander-akait
Copy link
Member

But yes, interesting, we don't use this import directly (ts generates it), look at source code https://github.com/webpack-contrib/css-minimizer-webpack-plugin/blob/master/src/utils.js#L8, looks like @types/cssnano is broken, we planned to add types to cssnano, but it is not implemented yet, it should fix the problem, I am afraid we can't fix it here

@MynockSpit
Copy link
Author

MynockSpit commented Dec 21, 2021

Oh dumb. I thought I saw it in my deps somewhere, but @types/postcss doesn't even exist.

This might be naive, but do we need that line at all? It doesn't appear to actually be used anywhere: https://github.com/search?q=CssNano+repo%3Awebpack-contrib%2Fcss-minimizer-webpack-plugin+NOT+filename%3A.md+NOT+filename%3A.json&type=Code&ref=advsearch&l=&l=

@alexander-akait
Copy link
Member

hm, can you run npm ls postcss, I think you have postcss v7 and types for postcss v7

@alexander-akait
Copy link
Member

But yes, you are right we don't need this line, give me time to investigate it

@MynockSpit
Copy link
Author

I haven't manually installed postcss, and as a result, I have three different versions. Looks like the one for css-minimizer-webpack-plugin is 8.4.5

├─┬ @storybook/addon-docs@6.4.9
│ ├─┬ @storybook/builder-webpack4@6.4.9
│ │ ├─┬ autoprefixer@9.8.8
│ │ │ └── postcss@7.0.39 deduped
│ │ ├─┬ css-loader@3.6.0
│ │ │ ├─┬ icss-utils@4.1.1
│ │ │ │ └── postcss@7.0.39 deduped
│ │ │ ├─┬ postcss-modules-extract-imports@2.0.0
│ │ │ │ └── postcss@7.0.39 deduped
│ │ │ ├─┬ postcss-modules-local-by-default@3.0.3
│ │ │ │ └── postcss@7.0.39 deduped
│ │ │ ├─┬ postcss-modules-scope@2.2.0
│ │ │ │ └── postcss@7.0.39 deduped
│ │ │ ├─┬ postcss-modules-values@3.0.0
│ │ │ │ └── postcss@7.0.39 deduped
│ │ │ └── postcss@7.0.39 deduped
│ │ ├─┬ postcss-flexbugs-fixes@4.2.1
│ │ │ └── postcss@7.0.39 deduped
│ │ ├─┬ postcss-loader@4.3.0
│ │ │ └── postcss@7.0.39 deduped
│ │ └── postcss@7.0.39
│ └─┬ @storybook/core@6.4.9
│   └─┬ @storybook/core-server@6.4.9
│     └─┬ @storybook/manager-webpack4@6.4.9
│       └─┬ css-loader@3.6.0
│         └── postcss@7.0.39 deduped
├─┬ @storybook/builder-webpack5@6.4.9
│ └─┬ css-loader@5.2.7
│   ├─┬ icss-utils@5.1.0
│   │ └── postcss@8.4.4 deduped
│   ├─┬ postcss-modules-extract-imports@3.0.0
│   │ └── postcss@8.4.4 deduped
│   ├─┬ postcss-modules-local-by-default@4.0.0
│   │ └── postcss@8.4.4 deduped
│   ├─┬ postcss-modules-scope@3.0.0
│   │ └── postcss@8.4.4 deduped
│   ├─┬ postcss-modules-values@4.0.0
│   │ └── postcss@8.4.4 deduped
│   └── postcss@8.4.4
├─┬ @storybook/manager-webpack5@6.4.9
│ └─┬ css-loader@5.2.7
│   ├─┬ icss-utils@5.1.0
│   │ └── postcss@8.4.4 deduped
│   ├─┬ postcss-modules-extract-imports@3.0.0
│   │ └── postcss@8.4.4 deduped
│   ├─┬ postcss-modules-local-by-default@4.0.0
│   │ └── postcss@8.4.4 deduped
│   ├─┬ postcss-modules-scope@3.0.0
│   │ └── postcss@8.4.4 deduped
│   ├─┬ postcss-modules-values@4.0.0
│   │ └── postcss@8.4.4 deduped
│   └── postcss@8.4.4
├─┬ css-loader@6.5.1
│ ├─┬ icss-utils@5.1.0
│ │ └── postcss@8.4.4 deduped
│ ├─┬ postcss-modules-extract-imports@3.0.0
│ │ └── postcss@8.4.4 deduped
│ ├─┬ postcss-modules-local-by-default@4.0.0
│ │ └── postcss@8.4.4 deduped
│ ├─┬ postcss-modules-scope@3.0.0
│ │ └── postcss@8.4.4 deduped
│ ├─┬ postcss-modules-values@4.0.0
│ │ └── postcss@8.4.4 deduped
│ └── postcss@8.4.4
└─┬ css-minimizer-webpack-plugin@3.1.4
  ├─┬ cssnano@5.0.14
  │ ├─┬ cssnano-preset-default@5.1.9
  │ │ ├─┬ css-declaration-sorter@6.1.3
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ cssnano-utils@2.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-calc@8.0.0
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-colormin@5.2.2
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-convert-values@5.0.2
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-discard-comments@5.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-discard-duplicates@5.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-discard-empty@5.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-discard-overridden@5.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-merge-longhand@5.0.4
  │ │ │ ├── postcss@8.4.5 deduped
  │ │ │ └─┬ stylehacks@5.0.1
  │ │ │   └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-merge-rules@5.0.3
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-minify-font-values@5.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-minify-gradients@5.0.3
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-minify-params@5.0.2
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-minify-selectors@5.1.0
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-normalize-charset@5.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-normalize-display-values@5.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-normalize-positions@5.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-normalize-repeat-style@5.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-normalize-string@5.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-normalize-timing-functions@5.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-normalize-unicode@5.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-normalize-url@5.0.4
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-normalize-whitespace@5.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-ordered-values@5.0.2
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-reduce-initial@5.0.2
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-reduce-transforms@5.0.1
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-svgo@5.0.3
  │ │ │ └── postcss@8.4.5 deduped
  │ │ ├─┬ postcss-unique-selectors@5.0.2
  │ │ │ └── postcss@8.4.5 deduped
  │ │ └── postcss@8.4.5 deduped
  │ └── postcss@8.4.5 deduped
  └── postcss@8.4.5

@alexander-akait
Copy link
Member

And can you run npm ls @types/postcss?

@alexander-akait
Copy link
Member

Something from dependencies install @types/postcss and ts get it instead of original ts files from postcss, but it is real weird...

@alexander-akait
Copy link
Member

I found a problem - https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/cssnano/package.json#L4, cssnano types are not updated for v5... let's move types directly

@MynockSpit
Copy link
Author

MynockSpit commented Dec 21, 2021

And can you run npm ls @types/postcss?

None:

└── (empty)

I don't think @types/postcss exists. At least, not anymore:

https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/postcss

@alexander-akait alexander-akait mentioned this issue Dec 21, 2021
6 tasks
@alexander-akait
Copy link
Member

Yep, types are broken, fixed #147

@alexander-akait
Copy link
Member

@MynockSpit
Copy link
Author

Works great! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants