next.js: next@canary - can't find module "webpack5"

What version of Next.js are you using?

canary

What version of Node.js are you using?

16.11.1

What browser are you using?

Brave

What operating system are you using?

Windows

How are you deploying your application?

NestJS / Express

Describe the Bug

next@canary can’t find the module “webpack5”

[10:53:32] Starting compilation in watch mode...

node_modules/next/dist/server/config-shared.d.ts:1:27 - error TS2307: Cannot find module 'webpack5' or its corresponding type declarations.

1 import type webpack5 from 'webpack5';
                            ~~~~~~~~~~

[10:53:37] Found 1 error. Watching for file changes.

Expected Behavior

next@canary can find the module and compiles without issues

To Reproduce

Create a express app with nextjs and typescript. replace next with next@canary error should occour

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 8
  • Comments: 22 (7 by maintainers)

Commits related to this issue

Most upvoted comments

for anyone else running into this in 12, we got around it by hacking an override of the ambient types with the following in module.d.ts file:

declare module 'next/dist/compiled/webpack/webpack' {
  export namespace webpack {
    interface Compiler {
      [key: string]: any;
    }
    interface Plugin {
      [key: string]: any;
    }
  }
  export namespace webpack5 {
    interface Configuration {
      [key: string]: any;
    }
  }
}

Still not fixed in the latest canary. Just bumping this up

v12.0.4-canary.0

It gives a new error:

TS2694: Namespace ‘“./node_modules/next/dist/compiled/webpack/webpack”.webpack5’ has no exported member ‘Compilation’.

26 createAssets(compilation: webpack5.Compilation, assets: any, envPerRoute: Map<string, string[]>): void;

@ijjk is it normal that webpack.d.ts only exports namespace webpack? image shouldn’t it export { webpack, loader, webpack4, webpack5 } ? image