由于依赖问题,离子启动失败
Posted
技术标签:
【中文标题】由于依赖问题,离子启动失败【英文标题】:Ionic start fails because of dependency issue 【发布时间】:2021-08-09 23:57:03 【问题描述】:我刚刚安装了 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 还很陌生,我似乎无法在此站点或 Internet 上的其他任何地方找到解决方案。
我尝试了--force
和--legacy-peer-deps
,但收到了同样的错误。
这个错误的原因是什么,我该如何解决?
我的节点、npm 和离子版本是:
$ node --version
v16.2.0
$ npm --version
7.13.0
$ ionic --version
6.16.1
【问题讨论】:
尝试安装npm i @ionic-native/core
【参考方案1】:
这是我的第一个猜测 - 安装更新版本的 postcss
,但不幸的是,这并没有为我解决问题。解决方案是从npm
的第7版降级到第6版。
npm install -g npm@6
【讨论】:
【参考方案2】:由于某种原因,我无法让它在节点版本16.2.0
上运行。
但是,使用节点版本管理器nvm
我安装了第二个节点实例,LTS 版本14.17.0
。
通过此次降级,设置过程正常进行。
nvm install 14.17.0
【讨论】:
非常适合我,带有 M1 的 macOS。 我也尝试过这个解决方案,但 14.x.0 版本在 Windows 上对我不起作用。 在 macOS (intel) 上也不适用于我。【参考方案3】:我遇到了这个错误并手动安装 postcss npm i postcss
修复了它,因为堆栈跟踪显示依赖项依赖于最新版本的 postcss version 8.2.15
,而发现的是 version 8.2.14
。
【讨论】:
【参考方案4】:在 node start 使用 npm v7.5.2 时遇到类似问题,并通过升级到 v7.22.0 得到修复。
【讨论】:
以上是关于由于依赖问题,离子启动失败的主要内容,如果未能解决你的问题,请参考以下文章
Tomcat 7 SEVERE:在 pom 中将 spring-data-jpa 添加到依赖项后,由于先前的错误,上下文 [] 启动失败