无法在 Powershell windows 上的新 Phoenix 项目中 运行 `npm install`

Unable to run `npm install` in fresh Phoenix project on Powershell windows

背景

我正在尝试 Phoenix LiveView project to learn how it works. To this extent, I have, in my windows 10 machine, installed Elixir and NPM via chocolatey。我也成功地 运行 命令:

$ mix archive.install hex phx_new
$ mix phx.new demo --live

问题

问题出现在 运行 执行第二个命令之后。完成后,我被告知要执行一些额外的步骤:

We are almost there! The following steps are missing:

    $ cd test_app
    $ cd assets && npm install && node node_modules/webpack/bin/webpack.js --mode development

具体来说,npm install 部分失败:

> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: webpack@5.18.0
npm ERR! node_modules/webpack
npm ERR!   dev webpack@"4.41.5" from the root project
npm ERR!   peer webpack@">=2" from babel-loader@8.2.2
npm ERR!   node_modules/babel-loader
npm ERR!     dev babel-loader@"^8.0.0" from the root project
npm ERR!   3 more (copy-webpack-plugin, css-loader, hard-source-webpack-plugin)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev mini-css-extract-plugin@"^0.9.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: webpack@4.46.0
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^4.4.0" from mini-css-extract-plugin@0.9.0
npm ERR!   node_modules/mini-css-extract-plugin
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\user\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user\AppData\Local\npm-cache\_logs21-01-29T08_41_13_010Z-debug.log

这是一个新项目。我很困惑为什么会这样。 如果我 运行 npm install --force 那么我会遇到一大堆错误,我想是因为这个问题。

问题

我该如何解决这个问题?

回答

这里的问题是 node-sass 版本。目前 Node 15 和那个包有一个错误。

https://elixirforum.com/t/unable-to-run-npm-install-in-fresh-phoenix-project-on-powershell-windows/37164/4?u=fl4m3ph03n1x

可以使用以下命令修复此问题:

npm i --legacy-peer-deps