uni-app cli 项目不支持 pnpm、Monorepo

daolsyd0  于 2021-11-27  发布在  Java
关注(0)|答案(17)|浏览(1649)

问题描述

cli创建的项目使用 pnpm 安装依赖无法启动

cli 创建的项目不能使用Monorepo lerna管理。依赖无法读取,报错 缺少 xxx 平台插件

复现步骤

[复现问题的步骤]
pnpm: 使用cli创建项目,使用pnpm安装依赖,启动项目
Monorepo: lerna init,在packages下创建cli项目,安装依赖后启动项目

ui7jx7zq

ui7jx7zq1#

uniapp 所有包都是 lerna 管理的

pw136qt2

pw136qt22#

有什么因果关系吗?

sqxo8psd

sqxo8psd3#

CLI 创建的 alpha 版已经支持 pnpm。

如运行报错,先检查上报一下环境信息。

npm run info
jogvjijk

jogvjijk4#

  1. CLI 创建的 alpha 版 里面的依赖都是 ^2.0.0 , pnpm i的时候会报下图的信息,并且安装失败,修改
    "@dcloudio/uni-mp-360": "^2.0.1-alpha-32920211110001", 后可以安装成功
    启动报下面信息
> Executing task: pnpm run serve <

> my-alpha-project@0.1.0 serve /Users/xxx/my-alpha-project
> npm run dev:h5

> my-alpha-project@0.1.0 dev:h5
> cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve

/Users/xxxx/my-alpha-project/node_modules/.pnpm/@dcloudio+vue-cli-plugin-uni@2.0.0/node_modules/@dcloudio/vue-cli-plugin-uni/lib/error-reporting.js:45
    err = err.replace(this._UNI_INPUT_DIR_REG, 'UNI_INPUT_DIR')
              ^

TypeError: err.replace is not a function
    at ErrorReport.report (/Users/xxx/my-alpha-project/node_modules/.pnpm/@dcloudio+vue-cli-plugin-uni@2.0.0/node_modules/@dcloudio/vue-cli-plugin-uni/lib/error-reporting.js:45:15)
    at report (/Users/xxx/my-alpha-project/node_modules/.pnpm/@dcloudio+vue-cli-plugin-uni@2.0.0/node_modules/@dcloudio/vue-cli-plugin-uni/lib/error-reporting.js:144:24)
    at process.<anonymous> (/Users/xxxx/my-alpha-project/node_modules/.pnpm/@dcloudio+vue-cli-plugin-uni@2.0.0/node_modules/@dcloudio/vue-cli-plugin-uni/lib/error-reporting.js:154:42)
    at process.emit (events.js:314:20)
    at process._fatalException (internal/process/execution.js:165:25)
 ELIFECYCLE  Command failed with exit code 7.
终端进程“zsh '-c', 'pnpm run serve'”已终止,退出代码: 1。

  1. @dcloudio/uni-mp-360 的依赖使用yarn安装的时候每次都要手动选择依赖(这个点是另外一个issue了)
  2. npm run info 返回以下信息
╰─ npm run info

> my-alpha-project@0.1.0 info
> node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js

uni-app v3.1.8
uni-app cli v2.0.0

Environment Info:

  System:
    OS: macOS High Sierra 10.13.4
    CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
  Binaries:
    Node: 12.22.0 - ~/.nvm/versions/node/v12.22.0/bin/node
    Yarn: 1.22.5 - ~/.yarn/bin/yarn
    npm: 8.1.3 - ~/.nvm/versions/node/v12.22.0/bin/npm
  Browsers:
    Chrome: 95.0.4638.69
    Firefox: Not Found
    Safari: 11.1
  npmPackages:
    @dcloudio/types: * => 2.5.13 
    @dcloudio/uni-app-plus: ^2.0.0 => 2.0.0 
    @dcloudio/uni-automator: ^2.0.0 => 2.0.0 
    @dcloudio/uni-cli-shared: ^2.0.0 => 2.0.0 
    @dcloudio/uni-h5: ^2.0.0 => 2.0.0 
    @dcloudio/uni-helper-json: * => 1.0.13 
    @dcloudio/uni-i18n: ^2.0.0 => 2.0.0 
    @dcloudio/uni-migration: ^2.0.0 => 2.0.0 
    @dcloudio/uni-mp-360: ^2.0.1-alpha-32920211110001 => 2.0.1-alpha-32920211110001 
    @dcloudio/uni-mp-alipay: ^2.0.0 => 2.0.0 
    @dcloudio/uni-mp-baidu: ^2.0.0 => 2.0.0 
    @dcloudio/uni-mp-kuaishou: ^2.0.0 => 2.0.0 
    @dcloudio/uni-mp-qq: ^2.0.0 => 2.0.0 
    @dcloudio/uni-mp-toutiao: ^2.0.0 => 2.0.0 
    @dcloudio/uni-mp-vue: ^2.0.0 => 2.0.0 
    @dcloudio/uni-mp-weixin: ^2.0.0 => 2.0.0 
    @dcloudio/uni-quickapp-native: ^2.0.0 => 2.0.0 
    @dcloudio/uni-quickapp-webview: ^2.0.0 => 2.0.0 
    @dcloudio/uni-stat: ^2.0.0 => 2.0.0 
    @dcloudio/uni-template-compiler: ^2.0.0 => 2.0.0 
    @dcloudio/vue-cli-plugin-hbuilderx: ^2.0.0 => 2.0.0 
    @dcloudio/vue-cli-plugin-uni: ^2.0.0 => 2.0.0 
    @dcloudio/vue-cli-plugin-uni-optimize: ^2.0.0 => 2.0.0 
    @dcloudio/webpack-uni-mp-loader: ^2.0.0 => 2.0.0 
    @dcloudio/webpack-uni-pages-loader: ^2.0.0 => 2.0.0 
    @vue/cli-plugin-babel: ~4.5.0 => 4.5.15 
    @vue/cli-plugin-typescript: * => 4.5.15 
    @vue/cli-service: ~4.5.0 => 4.5.15 
    @vue/shared: ^3.0.0 => 3.2.21 
    vue: ^2.6.11 => 2.6.14 
    vue-class-component: ^6.3.2 => 6.3.2 
    vue-property-decorator: ^8.0.0 => 8.5.1 
    vue-template-compiler: ^2.6.11 => 2.6.14 
    vuex: ^3.2.0 => 3.6.2 
  npmGlobalPackages:
    @vue/cli: Not Found
pxq42qpu

pxq42qpu5#

2.0.0 是一个错误的版本(已废弃),目前在部分用户那仍然可以安装到,正在排查和处理。

处理方式:将所有 uni 相关版本批量替换为 "2.0.0-alpha-32920211110001" 后重新安装依赖

vpfxa7rd

vpfxa7rd6#

  1. 修改了之后有 WARN 

  1. Error: Cannot find module '@dcloudio/uni-cli-i18n',解决:pnpm add @dcloudio/uni-cli-i18n
    走完上面两部可以正常运行了
  2. 2.0.0 的问题是cli的模板里面出了问题吧,dcloudio/uni-preset-vue仓库下没有看到相关的版本号指定,不知道是不是什么魔法还是我没找到
  3. 方便提供一下你测试用的 package.jsondevDependencies``dependencies部分吗?
  4. alpha最新的包应该是 2.0.1-alpha-32920211110001 吧,而不是 2.0.0-alpha-32920211110001
zfciruhq

zfciruhq7#

preset 仓库依赖版本为 "^2.0.0-alpha-32920211110001",但是实际部分用户仍然安装为 2.0.0,具体原因还未找到,所以准备调整依赖版本为:2.0.1-alpha-32920211110001,2.0.1-alpha-32920211110001 版本实际和 2.0.0-alpha-32920211110001 是同样内容,使用 2.0.0-alpha-32920211110001 即可,2.0.1-alpha-32920211110001 实际还未在模板采用。版本调整正准备进行,后续将放弃之前的历史包袱(承诺使用 update 命令升级),增加版本管理工具,采用语义化的版本号。

qmb5sa22

qmb5sa228#

我这刚创建了一个是这样

{
  "name": "cli-test-1112",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "npm run dev:h5",
    "build": "npm run build:h5",
    "build:app-plus": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build",
    "build:custom": "cross-env NODE_ENV=production uniapp-cli custom",
    "build:h5": "cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build",
    "build:mp-360": "cross-env NODE_ENV=production UNI_PLATFORM=mp-360 vue-cli-service uni-build",
    "build:mp-alipay": "cross-env NODE_ENV=production UNI_PLATFORM=mp-alipay vue-cli-service uni-build",
    "build:mp-baidu": "cross-env NODE_ENV=production UNI_PLATFORM=mp-baidu vue-cli-service uni-build",
    "build:mp-kuaishou": "cross-env NODE_ENV=production UNI_PLATFORM=mp-kuaishou vue-cli-service uni-build",
    "build:mp-lark": "cross-env NODE_ENV=production UNI_PLATFORM=mp-lark vue-cli-service uni-build",
    "build:mp-qq": "cross-env NODE_ENV=production UNI_PLATFORM=mp-qq vue-cli-service uni-build",
    "build:mp-toutiao": "cross-env NODE_ENV=production UNI_PLATFORM=mp-toutiao vue-cli-service uni-build",
    "build:mp-weixin": "cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build",
    "build:quickapp-native": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-native vue-cli-service uni-build",
    "build:quickapp-webview": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview vue-cli-service uni-build",
    "build:quickapp-webview-huawei": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview-huawei vue-cli-service uni-build",
    "build:quickapp-webview-union": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview-union vue-cli-service uni-build",
    "dev:app-plus": "cross-env NODE_ENV=development UNI_PLATFORM=app-plus vue-cli-service uni-build --watch",
    "dev:custom": "cross-env NODE_ENV=development uniapp-cli custom",
    "dev:h5": "cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve",
    "dev:mp-360": "cross-env NODE_ENV=development UNI_PLATFORM=mp-360 vue-cli-service uni-build --watch",
    "dev:mp-alipay": "cross-env NODE_ENV=development UNI_PLATFORM=mp-alipay vue-cli-service uni-build --watch",
    "dev:mp-baidu": "cross-env NODE_ENV=development UNI_PLATFORM=mp-baidu vue-cli-service uni-build --watch",
    "dev:mp-kuaishou": "cross-env NODE_ENV=development UNI_PLATFORM=mp-kuaishou vue-cli-service uni-build --watch",
    "dev:mp-lark": "cross-env NODE_ENV=development UNI_PLATFORM=mp-lark vue-cli-service uni-build --watch",
    "dev:mp-qq": "cross-env NODE_ENV=development UNI_PLATFORM=mp-qq vue-cli-service uni-build --watch",
    "dev:mp-toutiao": "cross-env NODE_ENV=development UNI_PLATFORM=mp-toutiao vue-cli-service uni-build --watch",
    "dev:mp-weixin": "cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch",
    "dev:quickapp-native": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-native vue-cli-service uni-build --watch",
    "dev:quickapp-webview": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview vue-cli-service uni-build --watch",
    "dev:quickapp-webview-huawei": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview-huawei vue-cli-service uni-build --watch",
    "dev:quickapp-webview-union": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview-union vue-cli-service uni-build --watch",
    "info": "node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js",
    "serve:quickapp-native": "node node_modules/@dcloudio/uni-quickapp-native/bin/serve.js",
    "test:android": "cross-env UNI_PLATFORM=app-plus UNI_OS_NAME=android jest -i",
    "test:h5": "cross-env UNI_PLATFORM=h5 jest -i",
    "test:ios": "cross-env UNI_PLATFORM=app-plus UNI_OS_NAME=ios jest -i",
    "test:mp-baidu": "cross-env UNI_PLATFORM=mp-baidu jest -i",
    "test:mp-weixin": "cross-env UNI_PLATFORM=mp-weixin jest -i"
  },
  "dependencies": {
    "@dcloudio/uni-app-plus": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-h5": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-helper-json": "*",
    "@dcloudio/uni-i18n": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-mp-360": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-mp-alipay": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-mp-baidu": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-mp-kuaishou": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-mp-lark": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-mp-qq": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-mp-toutiao": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-mp-vue": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-mp-weixin": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-quickapp-native": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-quickapp-webview": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-stat": "^2.0.0-alpha-32920211110001",
    "@vue/shared": "^3.0.0",
    "core-js": "^3.6.5",
    "flyio": "^0.6.2",
    "regenerator-runtime": "^0.12.1",
    "vue": "^2.6.11",
    "vuex": "^3.2.0"
  },
  "devDependencies": {
    "@babel/runtime": "~7.12.0",
    "@dcloudio/types": "*",
    "@dcloudio/uni-automator": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-cli-i18n": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-cli-shared": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-migration": "^2.0.0-alpha-32920211110001",
    "@dcloudio/uni-template-compiler": "^2.0.0-alpha-32920211110001",
    "@dcloudio/vue-cli-plugin-hbuilderx": "^2.0.0-alpha-32920211110001",
    "@dcloudio/vue-cli-plugin-uni": "^2.0.0-alpha-32920211110001",
    "@dcloudio/vue-cli-plugin-uni-optimize": "^2.0.0-alpha-32920211110001",
    "@dcloudio/webpack-uni-mp-loader": "^2.0.0-alpha-32920211110001",
    "@dcloudio/webpack-uni-pages-loader": "^2.0.0-alpha-32920211110001",
    "@vue/cli-plugin-babel": "^4.5.0",
    "@vue/cli-service": "^4.5.0",
    "babel-plugin-import": "^1.11.0",
    "cross-env": "^7.0.2",
    "jest": "^25.4.0",
    "mini-types": "*",
    "miniprogram-api-typings": "*",
    "postcss-comment": "^2.0.0",
    "vue-template-compiler": "^2.6.11"
  },
  "browserslist": [
    "Android >= 4.4",
    "ios >= 9"
  ],
  "uni-app": {
    "scripts": {}
  }
}
c9x0cxw0

c9x0cxw09#

在pnpm的工作空间packages下作为一个子包比如 package1

pnpm serve运行之后包如下提示

4:3 No overload matches this call.
  The last overload gave the following error.
    Argument of type '{ mpType: string; onLaunch(): void; onShow(): void; onHide(): void; }' is not assignable to parameter of type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<...>>'.
      Object literal may only specify known properties, and 'mpType' does not exist in type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<...>>'.
    2 | import Vue from 'vue';
    3 | export default Vue.extend({
  > 4 |   mpType: 'app',
      |   ^
    5 |   onLaunch() {
    6 |     console.log('App Launch');
    7 |   },
7lrncoxx

7lrncoxx10#

你这里不使用 pnpm(使用 yarn 或者 npm 安装依赖)是否能正常运行?

56lgkhnf

56lgkhnf11#

单独项目能否正常运行?

wgxvkvu9

wgxvkvu913#

你那再试下独立项目使用pnpm安装依赖是否能正常运行

gcmastyq

gcmastyq14#

vue create -p dcloudio/uni-preset-vue#alpha my-alpha-project 更新依赖后使用pnpm ,my-alpha-project 项目可以正常运行,但是我想用Monorepo 去管理,uniapp 项目
结构如下

packages/
      my-alpha-project
      my-alpha-project2
      other
pnpm-workspace.yaml
packages:
  - 'packages/**'

这个结构就会报 错误

jjjwad0x

jjjwad0x15#

好的,后续会处理一下兼容问题

另外,想了解一下这些仓库是什么关系,对应那种业务场景,能否透露一下?毕竟一般情况下每个 uni-app 项目都是单独的应用。

相关问题