Skip to content
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

Type error: Could not find a declaration file for module 'next/dist/compiled/webpack/webpack' #21390

Closed
elliottsj opened this issue Jan 20, 2021 · 9 comments · Fixed by #21785
Labels
bug Issue was opened via the bug report template.

Comments

@elliottsj
Copy link
Contributor

What version of Next.js are you using?

10.0.6-canary.6

What version of Node.js are you using?

14.15.4

What browser are you using?

N/A

What operating system are you using?

Linux

How are you deploying your application?

Vercel

Describe the Bug

When upgrading from v10.0.6-canary.0 to v10.0.6-canary.6, this error is raised:

./node_modules/.pnpm/next@10.0.6-canary.6_c39e9db791ea05e3ec4e0e74abb7a6b5/node_modules/next/dist/build/webpack/plugins/build-manifest-plugin.d.ts:1:25
Type error: Could not find a declaration file for module 'next/dist/compiled/webpack/webpack'. '/home/runner/work/elliott.dev/elliott.dev/node_modules/.pnpm/next@10.0.6-canary.6_c39e9db791ea05e3ec4e0e74abb7a6b5/node_modules/next/dist/compiled/webpack/webpack.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/next` if it exists or add a new declaration (.d.ts) file containing `declare module 'next/dist/compiled/webpack/webpack';`

> 1 | import { webpack } from 'next/dist/compiled/webpack/webpack';
    |                         ^
  2 | import { Rewrite } from '../../../lib/load-custom-routes';
  3 | export declare type ClientBuildManifest = Record<string, string[]>;
  4 | export default class BuildManifestPlugin {

See https://github.com/elliottsj/elliott.dev/pull/442/checks?check_run_id=1733030038

I am using pnpm, as well as tsconfig options "strict": true and "skipLibCheck": false.

Expected Behavior

No error should occur.

To Reproduce

See:

@elliottsj elliottsj added the bug Issue was opened via the bug report template. label Jan 20, 2021
@flybayer
Copy link
Contributor

I'm seeing this too

@aralroca
Copy link
Contributor

Same

kodiakhq bot pushed a commit that referenced this issue Feb 1, 2021
This should resolve the typing issues described in #21390 from the webpack inlining, by declaring `next/dist/compiled/webpack` in the main typing file as a source.
@zEh-
Copy link

zEh- commented Feb 1, 2021

@guybedford, still doesn't work for me with or without webpack as (dev-)dep.
Anyone else having luck?

$ yarn why next
=> Found "next@10.0.7-canary.0"

$ yarn why webpack
=> Found "webpack@4.46.0"

$ next build
../../node_modules/next/dist/build/webpack/plugins/build-manifest-plugin.d.ts:1:25
Type error: Could not find a declaration file for module 'next/dist/compiled/webpack/webpack'. '[...]/node_modules/next/dist/compiled/webpack/webpack.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/next` if it exists or add a new declaration (.d.ts) file containing `declare module 'next/dist/compiled/webpack/webpack';`

> 1 | import { webpack } from 'next/dist/compiled/webpack/webpack';
    |                         ^
  2 | import { Rewrite } from '../../../lib/load-custom-routes';
  3 | export declare type ClientBuildManifest = Record<string, string[]>;
  4 | export default class BuildManifestPlugin {
info  - Creating an optimized production build .child_process.js:655
    throw err;
    ^

@flybayer
Copy link
Contributor

flybayer commented Feb 1, 2021

Workaround, add this in your code somewhere:

declare namespace webpack {
   export type Compiler = any
   export type Plugin = any
 }
 declare module "next/dist/compiled/webpack/webpack" {
   export const webpack: any
 }

@heavenshell
Copy link

heavenshell commented Feb 2, 2021

When I set "skipLibCheck": false on tsconfig.json,
Type error: Could not find a declaration file for module 'next/dist/compiled/webpack/webpack' raised.
If I set "skipLibCheck": true works fine.

Should I always set "skipLibCheck": true?
I'd like set always skipLibCheck: false.

@guybedford
Copy link
Contributor

If the previous PR didn't capture the issue, perhaps someone here can share a full end to end replication for me as I wasn't able to replicate the issue with a basic app with a tsconfig.json as described. @elliottsj I also tried cloning your repo but wasn't able to see the issue there either.

Alternatively, could someone here verify if the approach in guybedford@39e7ffd seems like it might work, in which case we could go ahead and merge that.

@elliottsj
Copy link
Contributor Author

elliottsj commented Feb 2, 2021

@guybedford

git clone https://github.com/elliottsj/elliott.dev.git
cd elliott.dev/
git checkout next-10.0.7
# npm i -g pnpm
pnpm i
pnpm build

Tried the approach in guybedford@39e7ffd, but the error persists. This is also raised:

image

@guybedford
Copy link
Contributor

Thanks @elliottsj that was exactly the replication I needed, I've verified the fix in #21785 works against that case.

@kodiakhq kodiakhq bot closed this as completed in #21785 Feb 3, 2021
kodiakhq bot pushed a commit that referenced this issue Feb 3, 2021
This adds a simple typing definition to the Webpack ncc output.

Fixes #21390.
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
wiser-soft pushed a commit to wiser-soft/next.js that referenced this issue Sep 5, 2022
This adds a simple typing definition to the Webpack ncc output.

Fixes vercel/next.js#21390.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants