安装 next.js 时出现错误

Posted

技术标签:

【中文标题】安装 next.js 时出现错误【英文标题】:ERR while installing next.js 【发布时间】:2021-03-31 12:42:19 【问题描述】:

当我输入时

npx create-next-app

它会要求我给目录的名称,对吗?所以,我输入我想要的名称,然后让它运行。但它一直保持在这条线上。

然后在我之前执行“create-next-app”时。我同意

npm create-next-app job --use-nom

yarn create next-app job

还是报错。

当我尝试npm audit fix --force

它一直显示这些错误。

_________________________________________________________________________________________

npm WARN using --force Recommended protections disabled.

npm WARN audit Updating next to 9.4.4,which is a SemVer major change.

npm WARN ERESOLVE overriding peer dependency

npm WARN Found: react@17.0.1

npm WARN node_modules/react

npm WARN   peer react@"17.0.1" from react-dom@17.0.1

npm WARN   node_modules/react-dom

npm WARN     react-dom@"17.0.1" from the root project

npm WARN   1 more (the root project)

npm WARN

npm WARN Could not resolve dependency:

npm WARN peer react@"^16.6.0" from next@9.4.4

npm WARN node_modules/next

npm WARN   next@"9.4.4" from the root project

npm WARN ERESOLVE overriding peer dependency

npm WARN Found: react-dom@17.0.1

npm WARN node_modules/react-dom

npm WARN   react-dom@"17.0.1" from the root project

npm WARN

npm WARN Could not resolve dependency:

npm WARN peer react-dom@"^16.6.0" from next@9.4.4

npm WARN node_modules/next

npm WARN   next@"9.4.4" from the root project

npm WARN ERESOLVE overriding peer dependency

npm WARN Found: react@17.0.1

npm WARN node_modules/react

npm WARN   peer react@"17.0.1" from react-dom@17.0.1

npm WARN   node_modules/react-dom

npm WARN     react-dom@"17.0.1" from the root project

npm WARN   1 more (the root project)

npm WARN

npm WARN Could not resolve dependency:

npm WARN peer react@"^16.9.0" from @next/react-dev-overlay@9.4.4

npm WARN node_modules/next/node_modules/@next/react-dev-overlay

npm WARN   @next/react-dev-overlay@"9.4.4" from next@9.4.4

npm WARN   node_modules/next

npm WARN ERESOLVE overriding peer dependency

npm WARN Found: react@17.0.1

npm WARN node_modules/react

npm WARN   peer react@"17.0.1" from react-dom@17.0.1

npm WARN   node_modules/react-dom

npm WARN     react-dom@"17.0.1" from the root project

npm WARN   1 more (the root project)

npm WARN
npm WARN Could not resolve dependency:

npm WARN peer react@"^16.9.0" from @next/react-dev-overlay@9.4.4

npm WARN node_modules/next/node_modules/@next/react-dev-overlay

npm WARN   @next/react-dev-overlay@"9.4.4" from next@9.4.4

npm WARN   node_modules/next

npm WARN ERESOLVE overriding peer dependency

npm WARN Found: react-dom@17.0.1

npm WARN node_modules/react-dom

npm WARN   react-dom@"17.0.1" from the root project

npm WARN
npm WARN Could not resolve dependency:

npm WARN peer react-dom@"^16.9.0" from @next/react-dev-overlay@9.4.4

npm WARN node_modules/next/node_modules/@next/react-dev-overlay

npm WARN   @next/react-dev-overlay@"9.4.4" from next@9.4.4

npm WARN   node_modules/next

npm WARN ERESOLVE overriding peer dependency

npm WARN Found: react-dom@17.0.1

npm WARN node_modules/react-dom

npm WARN   react-dom@"17.0.1" from the root project

npm WARN
npm WARN Could not resolve dependency:

npm WARN peer react-dom@"^16.9.0" from @next/react-dev-overlay@9.4.4

npm WARN node_modules/next/node_modules/@next/react-dev-overlay


npm WARN   @next/react-dev-overlay@"9.4.4" from next@9.4.4


npm WARN   node_modules/next

npm WARN ERESOLVE overriding peer dependency

npm WARN Found: react@17.0.1

npm WARN node_modules/react

npm WARN   peer react@"17.0.1" from react-dom@17.0.1

npm WARN   node_modules/react-dom

npm WARN     react-dom@"17.0.1" from the root project

npm WARN   1 more (the root project)

npm WARN
npm WARN Could not resolve dependency:

npm WARN peer react@"15.x.x || 16.x.x" from styled-jsx@3.3.0

npm WARN node_modules/next/node_modules/styled-jsx

npm WARN   styled-jsx@"3.3.0" from next@9.4.4

npm WARN   node_modules/next

npm WARN ERESOLVE overriding peer dependency

npm WARN Found: react@17.0.1

npm WARN node_modules/react

npm WARN   peer react@"17.0.1" from react-dom@17.0.1

npm WARN   node_modules/react-dom

npm WARN     react-dom@"17.0.1" from the root project

npm WARN   1 more (the root project)

npm WARN
npm WARN Could not resolve dependency:

npm WARN peer react@"15.x.x || 16.x.x" from styled-jsx@3.3.0

npm WARN node_modules/next/node_modules/styled-jsx

npm WARN   styled-jsx@"3.3.0" from next@9.4.4

npm WARN   node_modules/next

npm WARN ERESOLVE overriding peer dependency

npm WARN Found: react@17.0.1

npm WARN node_modules/react

npm WARN   peer react@"17.0.1" from react-dom@17.0.1

npm WARN   node_modules/react-dom
npm WARN     react-dom@"17.0.1" from the root project

npm WARN   1 more (the root project)

npm WARN
npm WARN Could not resolve dependency:

npm WARN peer react@"^16.8.0" from use-subscription@1.4.1

npm WARN node_modules/next/node_modules/use-subscription

npm WARN   use-subscription@"1.4.1" from next@9.4.4

npm WARN   node_modules/next

npm WARN ERESOLVE overriding peer dependency

npm WARN Found: react@17.0.1

npm WARN node_modules/react

npm WARN   peer react@"17.0.1" from react-dom@17.0.1

npm WARN   node_modules/react-dom

npm WARN     react-dom@"17.0.1" from the root project

npm WARN   1 more (the root project)

npm WARN
npm WARN Could not resolve dependency:

npm WARN peer react@"^16.8.0" from use-subscription@1.4.1

npm WARN node_modules/next/node_modules/use-subscription

npm WARN   use-subscription@"1.4.1" from next@9.4.4

npm WARN   node_modules/next

npm WARN deprecated mkdirp@0.5.3: Legacy versions of mkdirp are no longer supported. Please update to 

mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)

npm WARN deprecated fsevents@2.1.3: Please update to v 2.2.x

npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure
 binaries. Upgrade to fsevents 2.

npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.

npm ERR! code 1

npm ERR! path C:\Users\Faijiuy\Desktop\University Classes_Materials\Senior Project 1\Test Next-
js\job\node_modules\@ampproject\toolbox-optimizer

npm ERR! command failed

npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node lib/warmup.js

npm ERR! internal/modules/cjs/loader.js:613

npm ERR!     throw err;
npm ERR!     ^
npm ERR!
npm ERR! Error: Cannot find module 'cross-fetch'

npm ERR! Require stack:

npm ERR! - C:\Users\Faijiuy\Desktop\University Classes_Materials\Senior Project 1\Test Next-js\job\node_modules\@ampproject\toolbox-optimizer\lib\DomTransformer.js


npm ERR! - C:\Users\Faijiuy\Desktop\University Classes_Materials\Senior Project 1\Test Next-js\job\node_modules\@ampproject\toolbox-optimizer\index.js

npm ERR! - C:\Users\Faijiuy\Desktop\University Classes_Materials\Senior Project 1\Test Next-js\job\node_modules\@ampproject\toolbox-optimizer\lib\warmup.js

npm ERR!     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:610:15)

npm ERR!     at Function.Module._load (internal/modules/cjs/loader.js:526:27)

npm ERR!     at Module.require (internal/modules/cjs/loader.js:666:19)

npm ERR!     at require (internal/modules/cjs/helpers.js:16:16)

npm ERR!     at Object.<anonymous> (C:\Users\Faijiuy\Desktop\University Classes_Materials\Senior Project 1\Test Next-js\job\node_modules\@ampproject\toolbox-optimizer\lib\DomTransformer.js:20:13)

npm ERR!     at Module._compile (internal/modules/cjs/loader.js:759:30)

npm ERR!     at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)

npm ERR!     at Module.load (internal/modules/cjs/loader.js:628:32)

npm ERR!     at Function.Module._load (internal/modules/cjs/loader.js:555:12)

npm ERR!     at Module.require (internal/modules/cjs/loader.js:666:19)


npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Faijiuy\AppData\Local\npm-cache\_logs\2020-12-21T17_49_46_033Z-debug.log
________________________________________________________________________________________________________

And, some other previous time. I also have try using yarn to do it.
But every time I do it the files keep missing or the command 'next' cannot be used internal/external. Even there are script tag show up in `package.json`, I cannot run yarn dev because `next` command is not recognized on internal/external

Sometime there problem like `chovidar, fesevent` cannot be use like 

- Sometime, it ask to install next-app

- Sometimes, they will ask to update fesevents, but I do not know how?

npm WARN deprecated fsevents@2.1.3: Please update to v 2.2.x

npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.

npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.

我也尝试卸载 Node.js 并安装旧版本的 Node.js

当前版本:12.0.0

Node.js 旧版测试:15.4.0

我已经尝试了所有可能的方法。我该如何解决这个问题?我需要安装新的 Node.js 吗?

【问题讨论】:

【参考方案1】:

可以在您的 package.json 中将您的 nextjs 版本更新为 9.5.0。 9.4.4 上的交叉提取存在一个尚未解决的依赖问题。您当前的 nextjs 版本显示为 9.4.4。

这应该可以解决问题

【讨论】:

以上是关于安装 next.js 时出现错误的主要内容,如果未能解决你的问题,请参考以下文章

尝试将 FontAwesome 放入正文时出现 Next.js 链接错误

使用`let cached = global.mongoose`时出现Next.js + Typescript + mongoose错误

在 Next.js 中动态导入模块时出现“forwardRef”错误

错误:使用 Next.js 应用程序部署到 Azure 时出现“需要域选项”

使用 React-testing-library 进行测试时出现 Next.js 路由器错误

尝试使用 next-connect 在 Next.js 中从 http://localhost:3000 重定向到 https://api.twitter.com 时出现 CORS 错误?