使用纱线进行新的 Nuxtjs 安装不起作用

Edg*_*ums 3 installation yarnpkg nuxt.js yarnpkg-v3

我只是使用(按照文档)创建一个新的 nuxt 应用程序:

\n
yarn create nuxt-app appname\n
Run Code Online (Sandbox Code Playgroud)\n

然后我切换到该目录并运行(按照文档):

\n
yarn dev\n
Run Code Online (Sandbox Code Playgroud)\n

并得到以下错误:

\n
 \xe2\x9c\x96 Nuxt Fatal Error                                                                                                                                                                                                \xe2\x94\x82\n   \xe2\x94\x82                                                                                                                                                                                                                     \xe2\x94\x82\n   \xe2\x94\x82   Error: @nuxt/components tried to access consola (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.                                                    \xe2\x94\x82\n   \xe2\x94\x82                                                                                                                                                                                                                     \xe2\x94\x82\n   \xe2\x94\x82   Required package: consola                                                                                                                                                                                         \xe2\x94\x82\n   \xe2\x94\x82   Required by: @nuxt/components@virtual:4eff43f3a560be194e6097f872c9d8ed0666b260b73fc7573cd09c38d17c2e2d252932f70636f4f4a6035fee79be6a699b4f9693d4a20ba4eb5c9b359f2413a9#npm:2.1.8 (via                             \xe2\x94\x82\n   \xe2\x94\x82   /home/ev/Documents/Projects/firebase-test/f-test/.yarn/__virtual__/@nuxt-components-virtual-7192147023/0/cache/@nuxt-components-npm-2.1.8-189d4bc3ff-b2ab70da20.zip/node_modules/@nuxt/components/dist/)          \xe2\x94\x82\n   \xe2\x94\x82                                                                                                                                                                                                                     \xe2\x94\x82\n   \xe2\x94\x82   Ancestor breaking the chain: nuxt@npm:2.15.7                                                                                                                                                                      \xe2\x94\x82\n   \xe2\x94\x82                                                                                                                                                                                                                     \xe2\x94\x82\n   \xe2\x94\x82                                                                                                                                                                                                                     \xe2\x94\x82\n   \xe2\x94\x82   Require stack:                                                                                                                                                                                                    \xe2\x94\x82\n   \xe2\x94\x82   -                                                                                                                                                                                                                 \xe2\x94\x82\n   \xe2\x94\x82   /home/ev/Documents/Projects/firebase-test/f-test/.yarn/__virtual__/@nuxt-components-virtual-7192147023/0/cache/@nuxt-components-npm-2.1.8-189d4bc3ff-b2ab70da20.zip/node_modules/@nuxt/components/dist/index.js   \n
Run Code Online (Sandbox Code Playgroud)\n

为什么会发生这种情况?\n我运行的是 Node v14.16.0 和yarn v3.0.0,并且使用的是 Linux Mint。

\n

小智 5

我可能有点晚回答最初提出问题的人,但我想我找到了问题的答案。

这是我在终端中使用ls -lahA第一次构建失败后可以看到的内容:

drwxrwxr-x 2 test test 4,0K 2022-06-29 15:50 components
drwxrwxr-x 7 test test 4,0K 2022-06-29 15:50 .git
drwxrwxr-x 2 test test 4,0K 2022-06-29 15:50 pages
drwxrwxr-x 2 test test 4,0K 2022-06-29 15:50 static
drwxrwxr-x 2 test test 4,0K 2022-06-29 15:50 store
drwxrwxr-x 4 test test 4,0K 2022-06-29 15:50 .yarn
-rw-rw-r-- 1 test test  207 2022-06-29 15:50 .editorconfig
-rw-rw-r-- 1 test test 1,3K 2022-06-29 15:50 .gitignore
-rw-rw-r-- 1 test test 1001 2022-06-29 15:50 nuxt.config.js
-rw-rw-r-- 1 test test  394 2022-06-29 15:50 package.json
-rwxr-xr-x 1 test test 1,1M 2022-06-29 15:50 .pnp.cjs <-----
-rw-r--r-- 1 test test 8,5K 2022-06-29 15:50 .pnp.loader.mjs <-----
-rw-rw-r-- 1 test test 2,8K 2022-06-29 15:50 README.md
-rw-rw-r-- 1 test test 375K 2022-06-29 15:50 yarn.lock
Run Code Online (Sandbox Code Playgroud)

为了解决这个问题,我删除了“.pnp.cjs”和“.pnp.loader.mjs”文件,并从其他项目添加了“.yarnrc.yml”文件。“.yarnrc.yml”文件仅包含一行:

nodeLinker: node-modules
Run Code Online (Sandbox Code Playgroud)

然后我在终端中编写了yarn ,一切正常,我可以再次使用yarn dev,一切正常。

我希望它有帮助。抱歉我的英语可能不太完美......