找不到插件依赖 @tarojs/plugin-platform-h5,请先在项目中安装

运行一个 Taro 的项目,安装完相关依赖后执行命令报错

执行步骤

  • yarn install
  • yarn run start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
正在执行任务: yarn run start 

yarn run v1.22.19
$ npm run dev:h5

> renthouse-taro@1.0.0 dev:h5
> npm run build:h5 -- --watch


> renthouse-taro@1.0.0 build:h5
> taro build --type h5 --watch

👽 Taro v3.6.25

找不到插件依赖 "@tarojs/plugin-platform-h5",请先在项目中安装,项目路径:D:\xxx\xxx\renthouse-taro
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

原因

因为我之前安装过 Taro 最新版本的 cli , 和现有的 Taro 版本不兼容

1
2
3
4
taro --version
👽 Taro v3.6.25

3.6.25

解决方案

  1. npm uninstall -g @tarojs/cli # 卸载 Trao
  2. npm install -g @tarojs/cli@3.0.29 # 安装指定版本 Trao
  3. 也有可能 nodejs 版本过低和 taro/cli 不兼容,nvm 切换 16.x 以上版本试试