华冬人工智能
华冬人工智能
  • 发布:2024-02-22 21:39
  • 更新:2024-03-06 22:13
  • 阅读:836

【报Bug】打包错误 Error: Cannot find module 'ts-loader'

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

手机系统: 全部

手机厂商: 华为

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: CLI

CLI版本号: 2.0.2-3090920231225001

测试过的手机:

无法打包,没到这一步

示例代码:

package.json

{  
  "name": "new3099",  
  "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-jd": "cross-env NODE_ENV=production UNI_PLATFORM=mp-jd 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:mp-xhs": "cross-env NODE_ENV=production UNI_PLATFORM=mp-xhs 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-jd": "cross-env NODE_ENV=development UNI_PLATFORM=mp-jd 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:mp-xhs": "cross-env NODE_ENV=development UNI_PLATFORM=mp-xhs 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": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-app-plus": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-h5": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-i18n": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-mp-360": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-mp-alipay": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-mp-baidu": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-mp-jd": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-mp-kuaishou": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-mp-lark": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-mp-qq": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-mp-toutiao": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-mp-vue": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-mp-weixin": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-mp-xhs": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-quickapp-native": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-quickapp-webview": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-stacktracey": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-stat": "^2.0.2-3090920231225001",  
    "@vue/shared": "^3.0.0",  
    "core-js": "^3.8.3",  
    "flyio": "^0.6.2",  
    "vue": ">= 2.6.14 < 2.7",  
    "vuex": "^3.2.0"  
  },  
  "devDependencies": {  
    "@dcloudio/types": "^3.3.2",  
    "@dcloudio/uni-automator": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-cli-i18n": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-cli-shared": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-helper-json": "*",  
    "@dcloudio/uni-migration": "^2.0.2-3090920231225001",  
    "@dcloudio/uni-template-compiler": "^2.0.2-3090920231225001",  
    "@dcloudio/vue-cli-plugin-hbuilderx": "^2.0.2-3090920231225001",  
    "@dcloudio/vue-cli-plugin-uni": "^2.0.2-3090920231225001",  
    "@dcloudio/vue-cli-plugin-uni-optimize": "^2.0.2-3090920231225001",  
    "@dcloudio/webpack-uni-mp-loader": "^2.0.2-3090920231225001",  
    "@dcloudio/webpack-uni-pages-loader": "^2.0.2-3090920231225001",  
    "@vue/cli-plugin-babel": "~5.0.0",  
    "@vue/cli-service": "~5.0.0",  
    "babel-plugin-import": "^1.11.0",  
    "cross-env": "^7.0.2",  
    "jest": "^25.4.0",  
    "postcss-comment": "^2.0.0",  
    "sass": "^1.49.8",  
    "sass-loader": "^8.0.2",  
    "vue-template-compiler": ">= 2.6.14 < 2.7"  
  },  
  "browserslist": [  
    "Android >= 4.4",  
    "ios >= 9"  
  ],  
  "uni-app": {  
    "scripts": {}  
  }  
}  

npm info

D:\Programs\nvm\npm\yarn.cmd run info  
yarn run v1.22.18  
$ node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js  
uni-app v3.99  
uni-app cli v2.0.2-3090920231225001  

Environment Info:                    

  System:                                                                                                   
    OS: Windows 10                                                                                          
    CPU: (4) x64 Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz                                                    
  Binaries:                                                                                                 
    Node: 14.18.2 - C:\Users\ADMINI~1\AppData\Local\Temp\yarn--1708609005798-0.016346315983656545\node.CMD  
    Yarn: 1.22.18 - C:\Users\ADMINI~1\AppData\Local\Temp\yarn--1708609005798-0.016346315983656545\yarn.CMD  
    npm: 6.14.17 - D:\Programs\nodejs\npm.CMD                                                               
  Browsers:                                                                                                 
    Edge: Not Found                                                                                         
  npmPackages:                                                                                              
    @dcloudio/types: ^3.3.2 => 3.4.7                                                                        
    @dcloudio/uni-app: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001                                    
    @dcloudio/uni-app-plus: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001                               
    @dcloudio/uni-app-plus-nvue:  0.0.1                                                                     
    @dcloudio/uni-app-plus-nvue-v8:  0.0.1  
    @dcloudio/uni-automator: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-cli-i18n: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-cli-shared: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-h5: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-helper-json: * => 1.0.13  
    @dcloudio/uni-i18n: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-migration: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-mp-360: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-mp-alipay: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-mp-baidu: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-mp-jd: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-mp-kuaishou: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-mp-lark: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-mp-qq: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-mp-toutiao: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-mp-vue: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-mp-weixin: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-mp-xhs: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-quickapp-native: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-quickapp-webview: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-stacktracey: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-stat: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/uni-template-compiler: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/vue-cli-plugin-hbuilderx: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/vue-cli-plugin-uni: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/vue-cli-plugin-uni-optimize: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/webpack-uni-mp-loader: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @dcloudio/webpack-uni-nvue-loader:  0.0.1  
    @dcloudio/webpack-uni-pages-loader: ^2.0.2-3090920231225001 => 2.0.2-3090920231225001  
    @hap-toolkit/dsl-vue:  0.6.13  
    @vue/babel-helper-vue-jsx-merge-props:  1.4.0  
    @vue/babel-helper-vue-transform-on:  1.2.1  
    @vue/babel-plugin-jsx:  1.2.1  
    @vue/babel-plugin-resolve-type:  1.2.1  
    @vue/babel-plugin-transform-vue-jsx:  1.4.0  
    @vue/babel-preset-app:  5.0.8  
    @vue/babel-preset-jsx:  1.4.0  
    @vue/babel-sugar-composition-api-inject-h:  1.4.0  
    @vue/babel-sugar-composition-api-render-instance:  1.4.0  
    @vue/babel-sugar-functional-vue:  1.4.0  
    @vue/babel-sugar-inject-h:  1.4.0  
    @vue/babel-sugar-v-model:  1.4.0  
    @vue/babel-sugar-v-on:  1.4.0  
    @vue/cli-overlay:  5.0.8  
    @vue/cli-plugin-babel: ~5.0.0 => 5.0.8  
    @vue/cli-plugin-router:  5.0.8  
    @vue/cli-plugin-vuex:  5.0.8  
    @vue/cli-service: ~5.0.0 => 5.0.8  
    @vue/cli-shared-utils:  5.0.8  
    @vue/compiler-core:  3.4.19  
    @vue/compiler-dom:  3.4.19  
    @vue/compiler-sfc:  3.4.19  
    @vue/compiler-ssr:  3.4.19  
    @vue/component-compiler-utils:  3.3.0 (3.3.0)  
    @vue/composition-api:  1.7.0  
    @vue/devtools-api:  6.0.0-beta.15  
    @vue/shared: ^3.0.0 => 3.4.19  
    @vue/web-component-wrapper:  1.3.0  
    mpvue-page-factory:  1.0.1  
    mpvue-template-compiler:  1.0.13  
    uni-h5-vue:  2.6.10  
    uni-mp-vue:  2.6.10  
    vue: >= 2.6.14 < 2.7 => 2.6.14  
    vue-hot-reload-api:  2.3.4  
    vue-loader:  17.4.2 (15.11.1, 15.11.1, 17.4.2)  
    vue-router:  3.0.1  
    vue-style-loader:  4.1.3 (4.1.3)  
    vue-template-compiler: >= 2.6.14 < 2.7 => 2.6.14 (2.7.16, 2.6.14)  
    vue-template-es2015-compiler:  1.9.1  
    vue3:  1.0.0  
    vuex: ^3.2.0 => 3.6.2 (3.6.2)  
  npmGlobalPackages:  
    @vue/cli: Not Found  

Done in 6.93s.  

进程已结束,退出代码为 0  

操作步骤:

升级到2.0.2-3090920231225001后运行build:app-plus

预期结果:

正常构建

实际结果:

报错信息如下

D:\Programs\nvm\npm\yarn.cmd run build:app-plus  
yarn run v1.22.18  
$ cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build  

​已开启 uni统计2.0 版本​  

​【重要】因 HBuilderX 3.4.9 版本起,uni统计2.0 调整了安卓端 deviceId 获取方式,导致 uni统计2.0 App-Android平台部分统计数据不准确。如使用了HBuilderX 3.4.9 - 3.6.4版本且开通了uni统计2.0的应用,需要使用HBuilderX3.6.7及以上版本重新发  
布应用并升级 uniAdmin 云函数解决,详见:https://ask.dcloud.net.cn/article/40097​  

3.99  

✔  开始编译当前项目至 app-plus 平台...  
 ERROR  Error: Cannot find module 'ts-loader'  
        Require stack:  
        - E:\Works\uni\new3099\node_modules\@dcloudio\vue-cli-plugin-hbuilderx\build\webpack.nvue.conf.js  
        - E:\Works\uni\new3099\node_modules\@dcloudio\vue-cli-plugin-uni\commands\build.js  
        - E:\Works\uni\new3099\node_modules\@dcloudio\vue-cli-plugin-uni\index.js  
        - E:\Works\uni\new3099\node_modules\@vue\cli-service\lib\Service.js  
        - E:\Works\uni\new3099\node_modules\@vue\cli-service\bin\vue-cli-service.js  
Error: Cannot find module 'ts-loader'  
Require stack:  
- E:\Works\uni\new3099\node_modules\@dcloudio\vue-cli-plugin-hbuilderx\build\webpack.nvue.conf.js  
- E:\Works\uni\new3099\node_modules\@dcloudio\vue-cli-plugin-uni\commands\build.js  
- E:\Works\uni\new3099\node_modules\@dcloudio\vue-cli-plugin-uni\index.js  
- E:\Works\uni\new3099\node_modules\@vue\cli-service\lib\Service.js  
- E:\Works\uni\new3099\node_modules\@vue\cli-service\bin\vue-cli-service.js  
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)  
    at Function.Module._resolveFilename (E:\Works\uni\new3099\node_modules\module-alias\index.js:49:29)  
    at Function.resolve (internal/modules/cjs/helpers.js:99:19)  
    at Object.<anonymous> (E:\Works\uni\new3099\node_modules\@dcloudio\vue-cli-plugin-hbuilderx\build\webpack.nvue.conf.js:359:21)  
    at Module._compile (internal/modules/cjs/loader.js:1085:14)  
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)  
    at Module.load (internal/modules/cjs/loader.js:950:32)  
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)  
    at Module.require (internal/modules/cjs/loader.js:974:19)  
    at require (internal/modules/cjs/helpers.js:93:18)  
    at build (E:\Works\uni\new3099\node_modules\@dcloudio\vue-cli-plugin-uni\commands\build.js:182:25)  
    at async E:\Works\uni\new3099\node_modules\@dcloudio\vue-cli-plugin-uni\commands\build.js:80:5  
error Command failed with exit code 1.  
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.  

进程已结束,退出代码为 1  

bug描述:

问题在升级到2.0.2-3090920231225001时出现的,因为公告要求升级。
但是升级后build:app-plus 命令报错,同理在HBuildX内也不能发布APP。

我按照官网的命令又建了一个项目,仍然不行。
很急,因为公告说2月29号一键登录就用不了了。

2024-02-22 21:39 负责人:YUANRJ 分享
已邀请:

最佳回复

DCloud

DCloud

HBuilderX 4.02.2024030621-alpha 已修复。

  • 笔袋App

    正式版啥时候出呐

    2024-03-06 23:28

华冬人工智能

华冬人工智能 (作者)

按官网模板新建的hello-uni-app也是如此,急!

YUANRJ

YUANRJ

感谢反馈,已确认问题,后续会修复。你可以在根目录下install ts-loader临时解决。

临时解决方案:
把刚才下载的依赖卸载掉,替换附件文件到/node_modules/@dcloudio/vue-cli-plugin-hbuilderx/build/,然后重新运行。

  • 华冬人工智能 (作者)

    你好,yarn add -D ts-loader typescript后确实能跑起来,但是多出很多webpack相关的警告,还有这种

    warning in ./src/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-uni.vue


    The requested module './mescroll-uni.vue?vue&type=script&lang=js&' contains conflicting star exports for the name '__esModule' with the previous requested module './mescroll-uni.vue?vue&type=renderjs&module=renderBiz&lang=js&'


    并且导入真机运行仍然显示不出来

    2024-02-23 18:15

  • 华冬人工智能 (作者)

    最近几个版本webpack版本是有升级吗,能回退吗?项目太大,这些改动很难找到原因解决的

    2024-02-23 18:21

  • YUANRJ

    回复 华冬人工智能: 前两个版本vue2 nvue支持了ts,可能在cli工程中有些兼容性问题,我这边再排查下

    2024-02-23 18:35

  • YUANRJ

    回复 华冬人工智能: 已更新回复,再试试

    2024-02-23 19:53

  • 常乐Y

    回复 YUANRJ: 你好,请问一下为什么我使用subnvue就报错ERROR Error: Cannot find module 'ts-loader'

    10:43:05.252 Require stack:

    10:43:05.256 - D:\Vue2\HbuilderX\练习\11.22\shop\wowoDigitalman\node_modules\@dcloudio\vue-cli-plugin-hbuilderx\build\webpack.nvue.conf.js

    10:43:05.278 - D:\Vue2\HbuilderX\练习\11.22\shop\wowoDigitalman\node_modules\@dcloudio\vue-cli-plugin-uni\commands\build.js

    10:43:05.289 - D:\Vue2\HbuilderX\练习\11.22\shop\wowoDigitalman\node_modules\@dcloudio\vue-cli-plugin-uni\index.js

    10:43:05.304 - D:\Vue2\HbuilderX\练习\11.22\shop\wowoDigitalman\node_modules\@vue\cli-service\lib\Service.js

    10:43:05.304 - D:\Vue2\HbuilderX\练习\11.22\shop\wowoDigitalman\node_modules\@vue\cli-service\bin\vue-cli-service.js

    是cli项目,如果不使用subnvue就不报错,是什么问题呢

    2024-04-09 10:47

  • 1***@163.com

    回复 常乐Y: 你解决了吗?

    2024-07-24 14:23

要回复问题请先登录注册