美文网首页
记taro编译微信小程序失败的坑

记taro编译微信小程序失败的坑

作者: 清平乐啊 | 来源:发表于2021-06-25 16:21 被阅读0次

该文档写于2021.6.25

1.taro全局安装

使用npm,yarn都失败之后,建议使用cnpm
npm install -g @tarojs/cli
yarn global add @tarojs/cli

在cmd命令行里面查看taro --version没有任何输出
使用Git Bash Here查看,No such file or directory
这就表示taro没装上...

那使用淘宝镜像全局装taro
cnpm install -g @tarojs/cli

在cmd里面查看


image.png

在Git Bash Here里面


image.png

2.在文件目录下编译taro文件失败,报错

各种错误,各种依赖问题,报错最多的是:

TypeError: ctx.modifyWebpackChain is not a function
    at exports.default (D:\work\smart_aide\node_modules\@tarojs\plugin-sass\dist\index.js:14:9)
    at Object.callPlugin (D:\work\smart_aide\node_modules\@tarojs\cli\src\util\npm.js:122:10)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
编译  所有页面
(node:15584) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'pages' of undefined
    at buildPages (D:\work\smart_aide\node_modules\@tarojs\cli\src\weapp.js:1187:27)
    at Object.build (D:\work\smart_aide\node_modules\@tarojs\cli\src\weapp.js:2209:9)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:15584) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:15584) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

这一堆也不知道是啥,百度很多说法是什么版本不统一,使劲升版本,降版本,都不行
终于看看了官方文档,再回过头去看自己的项目运行明白了
(1)项目依赖的taro版本与运行项目时候不一致
官方文档说:


image.png

(2)taro多版本共存


image.png
最后,注意看通过yarn或者npm运行项目的taro版本是v1.2.15,坑!
yarn dev:weapp
npm run build:weapp
image.png

那就使用taro命令!!!

taro build --type weapp --watch
image.png
OK,搞定,困扰了一晚上加一上午和下午俩小时的问题,是真的坑!
总结:taro运行项目的版本大于或等于package.json文件的taro版本(就是项目依赖的版本)!
附:(官网文档链接)[https://taro-docs.jd.com/taro/docs/GETTING-STARTED]

相关文章

网友评论

      本文标题:记taro编译微信小程序失败的坑

      本文链接:https://www.haomeiwen.com/subject/lnroyltx.html