npm.cmd run build:mp-weixin
报错了
uni-app-xiaotuxian@0.0.0 build:mp-weixin
uni build -p mp-weixin
‘uni’ 不是内部或外部命令,也不是可运行的程序
或批处理文件。
说明你的系统找不到 uni 命令,原因可能是 没有全局安装 @vue/cli-service 或 @dcloudio/uni-app 的 CLI 工具,或者环境变量未正确配置
输入命令
npx uni build -p mp-weixin
确认输入 y
继续报错
TypeError: Cannot assign to read only property 'name' of function 'function factory() {
factory.Command = factory.Command || require('./command/'+ folder);
var command =...<omitted>... }'
at map (C:\Users\admins\AppData\Local\npm-cache\_npx\ce2176121bc60ff1\node_modules\uni\index.js:113:16)
at Array.map (<anonymous>)
at Object.<anonymous> (C:\Users\admins\AppData\Local\npm-cache\_npx\ce2176121bc60ff1\node_modules\uni\index.js:92:4)
at Module._compile (node:internal/modules/cjs/loader:1554:14)
at Object..js (node:internal/modules/cjs/loader:1706:10)
at Module.load (node:internal/modules/cjs/loader:1289:32)
at Function._load (node:internal/modules/cjs/loader:1108:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)
at Module.require (node:internal/modules/cjs/loader:1311:12)
Node.js v22.14.0
问题本质
uni@0.0.6 是一个 第三方社区包,并不是 DCloud 官方的 uni-app CLI 工具,它的代码并不兼容新版本的 Node.js,特别是 Node.js v22 中加强了函数属性保护(不能随便改 name)。
解决
npm install
npm install @vue/cli-service -D
npm install @dcloudio/uni-app -D
报错就绕过依赖
npm install --legacy-peer-deps
npm run build:mp-weixin
应该就是构筑完成了,可以打开微信开发者工具访问了