[英]Nextjs with typescript
Nextjs with typescript show some error on deploy moment that does not show in development moment like that:带有 typescript 的 Nextjs 在部署时刻显示了一些错误,而在开发时刻没有显示这样的错误:
13:09:26 Failed to compile.
13:09:26 ./node_modules/next/dist/build/webpack/plugins/pages-manifest-plugin.d.ts:1:34
13:09:26 Type error: Could not find a declaration file for module 'webpack'. '/vercel/36bc1d70/node_modules/webpack/lib/webpack.js' implicitly has an 'any' type.
13:09:26 Try `npm install @types/webpack` if it exists or add a new declaration (.d.ts) file containing `declare module 'webpack';`
13:09:26 [0m[31m[1m>[22m[39m[90m 1 | [39m[36mimport[39m { [33mCompiler[39m[33m,[39m [33mPlugin[39m } from [32m'webpack'[39m[33m;[39m[0m
13:09:26 [0m [90m | [39m [31m[1m^[22m[39m[0m
13:09:26 [0m [90m 2 | [39m[36mexport[39m declare type [33mPagesManifest[39m [33m=[39m {[0m
13:09:26 [0m [90m 3 | [39m [page[33m:[39m string][33m:[39m string[33m;[39m[0m
13:09:26 [0m [90m 4 | [39m}[33m;[39m[0m
13:09:26 error Command failed with exit code 1.
13:09:26 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
13:09:26 Error: Command "yarn run vercel-build" exited with 1
13:09:28 Done with "package.json" ```
安装明确类型的 webpack 包, @types/webpack
As a bit of advice, for an easy and simple way to use typescript in NextJS.作为一点建议,在 NextJS 中使用打字稿的简单方法。 After
npx create-next-app your-app-name
, you can use this simple library npx next-to-ts
to avoid error.在
npx create-next-app your-app-name
,您可以使用这个简单的库npx next-to-ts
来避免错误。
firstly, you can install @types/webpack easily首先,你可以很容易地安装@types/webpack
npm install @types/webpack
NextJS uses Webpack, and this happens when you have incompletely installed project dependencies. NextJS 使用 Webpack,当您没有完全安装项目依赖项时会发生这种情况。 First of all, install all the packages with the
npm i
command, and if the problem is not solved, see which packages it wants and install them one by one.首先用
npm i
命令安装所有的包,如果问题还没有解决,看它要哪些包,一个一个安装。
You may have a typo in the Package.json
file and maybe it is not visible and check that you do not have a unusual character or typo您可能在
Package.json
文件中有一个拼写错误,它可能不可见,请检查您没有不寻常的字符或拼写错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.