Skip to content

unplugin, vite, pnpm (TS2307: Cannot find module 'webpack' or its corresponding type declarations) #36

Description

@charles-allen

TL;DR

I'm using Vite. My build complains Cannot find webpack. It seems strange that I need webpack types.

Background / context

I'm using unplugin-icons in a Vite / Vue 3 / TypeScript project. This is my build script:

"build": "vue-tsc --project tsconfig.build.json --noEmit && vite build",

I'm trying to migrate to pnpm; now the build fails (I assume because pnpm disallows coincidental resolution of @types/webpack from another dep):

../../node_modules/.pnpm/unplugin@0.2.19_vite@2.6.13/node_modules/unplugin/dist/index.d.ts:3:49 - error TS2307: Cannot find module 'webpack' or its corresponding type declarations.

3 import { Compiler, WebpackPluginInstance } from 'webpack';
                                                  ~~~~~~~~~

../../node_modules/.pnpm/unplugin@0.2.19_vite@2.6.13/node_modules/unplugin/dist/index.d.ts:4:45 - error TS2307: Cannot find module 'webpack' or its corresponding type declarations.

4 export { Compiler as WebpackCompiler } from 'webpack';
                                              ~~~~~~~~~

../../node_modules/.pnpm/webpack-virtual-modules@0.4.3/node_modules/webpack-virtual-modules/lib/index.d.ts:1:31 - error TS2307: Cannot find module 'webpack' or its corresponding type declarations.

1 import type { Compiler } from 'webpack';
                                ~~~~~~~~~

Solutions?

I can see that I have unplugin@0.2.19_vite@2.6.13 (Vite-specific) in my node_modules/.pnpm directory. But inside that is a plain copy of unplugin which exports index.d.ts pointing at webpack. Which of these is the intended solution?

  1. I should pnpm -D @types/webpack
  2. I should add --skipLibCheck to my build script
  3. Something else

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions