Ionic启动失败,因为存在依赖问题。

4
我刚刚使用安装了Ionic。
npm install -g @ionic/cli

当我尝试运行时

ionic start ionic-test-app

初始化失败,提示 npm 依赖错误。与名为 postcss 的包的版本不正确有关。

$ ionic start ionic-test-app

Pick a framework! 

Please select the JavaScript framework to use for your new app. To bypass this prompt next time,
supply a value for the --type option.

? Framework: Angular

Let's pick the perfect starter template! 

Starter templates are ready-to-go Ionic apps that come packed with everything you need to build your
app. To bypass this prompt next time, supply template, the second argument to ionic start.

? Starter template: blank
? ./ionic-test-app exists. Overwrite? Yes
 Preparing directory ./ionic-test-app in 6.79ms
 Downloading and extracting blank starter in 188.52ms
? Integrate your new app with Capacitor to target native iOS and Android? Yes
> ionic integrations enable capacitor --quiet -- ionic-test-app io.ionic.starter
> npm i --save -E @capacitor/core@latest
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: postcss@8.2.14
npm ERR! node_modules/postcss
npm ERR!   postcss@"8.2.14" from @angular-devkit/build-angular@0.1102.13
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"~0.1102.4" from the root project
npm ERR!     peer @angular-devkit/build-angular@"^0.1102.4" from @ionic/angular-toolkit@3.1.1
npm ERR!     node_modules/@ionic/angular-toolkit
npm ERR!       dev @ionic/angular-toolkit@"^3.1.1" from the root project
npm ERR!   peer postcss@"^8.1.0" from autoprefixer@10.2.4
npm ERR!   node_modules/autoprefixer
npm ERR!     autoprefixer@"10.2.4" from @angular-devkit/build-angular@0.1102.13
npm ERR!     node_modules/@angular-devkit/build-angular
npm ERR!       dev @angular-devkit/build-angular@"~0.1102.4" from the root project
npm ERR!       1 more (@ionic/angular-toolkit)
npm ERR!   9 more (css-loader, cssnano, postcss-import, postcss-loader, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer postcss@"^8.2.15" from cssnano-preset-default@5.1.0
npm ERR! node_modules/cssnano/node_modules/cssnano-preset-default
npm ERR!   cssnano-preset-default@"^5.0.1" from cssnano@5.0.2
npm ERR!   node_modules/cssnano
npm ERR!     cssnano@"5.0.2" from @angular-devkit/build-angular@0.1102.13
npm ERR!     node_modules/@angular-devkit/build-angular
npm ERR!       dev @angular-devkit/build-angular@"~0.1102.4" from the root project
npm ERR!       1 more (@ionic/angular-toolkit)
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 /home/sekthor/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/sekthor/.npm/_logs/2021-05-20T17_05_21_790Z-debug.log
[ERROR] An error occurred while running subprocess npm.
        
        npm i --save -E @capacitor/core@latest exited with exit code 1.
        
        Re-running this command with the --verbose flag may provide more information.

Installing dependencies may take several minutes.

  ──────────────────────────────────────────────────────────────────────────────

         Ionic Advisory, tailored solutions and expert services by Ionic

                             Go to market faster 
                    Real-time troubleshooting and guidance 
        Custom training, best practices, code and architecture reviews 
      Customized strategies for every phase of the development lifecycle 

                          https://ion.link/advisory  

  ──────────────────────────────────────────────────────────────────────────────


> npm i
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: postcss@8.2.14
npm ERR! node_modules/postcss
npm ERR!   postcss@"8.2.14" from @angular-devkit/build-angular@0.1102.13
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"~0.1102.4" from the root project
npm ERR!     peer @angular-devkit/build-angular@"^0.1102.4" from @ionic/angular-toolkit@3.1.1
npm ERR!     node_modules/@ionic/angular-toolkit
npm ERR!       dev @ionic/angular-toolkit@"^3.1.1" from the root project
npm ERR!   peer postcss@"^8.1.0" from autoprefixer@10.2.4
npm ERR!   node_modules/autoprefixer
npm ERR!     autoprefixer@"10.2.4" from @angular-devkit/build-angular@0.1102.13
npm ERR!     node_modules/@angular-devkit/build-angular
npm ERR!       dev @angular-devkit/build-angular@"~0.1102.4" from the root project
npm ERR!       1 more (@ionic/angular-toolkit)
npm ERR!   9 more (css-loader, cssnano, postcss-import, postcss-loader, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer postcss@"^8.2.15" from cssnano-preset-default@5.1.0
npm ERR! node_modules/cssnano/node_modules/cssnano-preset-default
npm ERR!   cssnano-preset-default@"^5.0.1" from cssnano@5.0.2
npm ERR!   node_modules/cssnano
npm ERR!     cssnano@"5.0.2" from @angular-devkit/build-angular@0.1102.13
npm ERR!     node_modules/@angular-devkit/build-angular
npm ERR!       dev @angular-devkit/build-angular@"~0.1102.4" from the root project
npm ERR!       1 more (@ionic/angular-toolkit)
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 /home/sekthor/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/sekthor/.npm/_logs/2021-05-20T17_05_28_760Z-debug.log
[ERROR] An error occurred while running subprocess npm.
        
        npm i exited with exit code 1.
        
        Re-running this command with the --verbose flag may provide more information.

我对npm比较陌生,但在这个网站和互联网上都找不到解决方案。

我尝试了--force--legacy-peer-deps两种方法,但是都收到了相同的错误。

这个错误的原因是什么,怎么解决?

我的node、npm和ionic版本如下:

$ node --version
v16.2.0
$ npm --version
7.13.0
$ ionic --version
6.16.1

1
尝试安装 npm i @ionic-native/core - Ravi Ashara
4个回答

2
由于某些原因,我无法在 node 版本 16.2.0 上使其正常工作。但是,使用 node 版本管理器 nvm,我安装了第二个实例的 node,即 LTS 版本 14.17.0。通过这种降级方式,设置过程可以正常运行。
nvm install 14.17.0

对我来说非常完美,使用M1芯片的macOS系统。 - Lewis
我也尝试过这个解决方案,但是在Windows上14.x.0版本对我不起作用。 - Daniel
我在macOS (intel)上也无法运行。 - tmuecksch

2

这是我最初的猜测 - 安装一个更新版本的 postcss,但不幸的是,这对我没有解决问题。解决方案是将 npm 的版本从 7 降级到版本 6。

    npm install -g npm@6

1

我遇到了这个错误,手动安装postcss npm i postcss 可以解决问题,因为堆栈跟踪显示一个依赖性依赖于最新版本的postcss版本8.2.15,但实际找到的是版本8.2.14


0

我曾经遇到过类似的问题,使用 npm v7.5.2 启动 node 时出现了问题,但通过升级到 v7.22.0 版本解决了该问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接