我刚刚安装了 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
答案 0 :(得分:2)
这是我的第一个猜测 - 安装更新版本的 postcss
,但不幸的是这并没有为我解决。解决方案是从 npm
的版本 7 降级到版本 6。
npm install -g npm@6
答案 1 :(得分:1)
我遇到了这个错误并手动安装 postcss npm i postcss
修复了它,因为堆栈跟踪显示依赖项依赖于最新版本的 postcss version 8.2.15
,并且发现的是 version 8.2.14
。< /p>