Cannot read properties of undefined (reading 'hooks')

记录解决方案

问题描述:

thread-loaderts-loader同时使用时,可能会导致编译时出现一个奇怪的报错:

ERROR in ./xxx/xxx/xxx.tsx
Module build failed (from ./node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 2)
Cannot read properties of undefined (reading 'hooks')
    at PoolWorker.fromErrorObj (H:\xxx\node_modules\thread-loader\dist\WorkerPool.js:344:12)
    at H:\xxx\node_modules\thread-loader\dist\WorkerPool.js:217:29
    at Object.initializeInstance (H:\xxx\node_modules\ts-loader\dist\instances.js:271:31)
    at successLoader (H:\xxx\node_modules\ts-loader\dist\index.js:26:17)
    at Object.loader (H:\xxx\node_modules\ts-loader\dist\index.js:23:5)

做过的尝试:

  1. 直接把thread-loader去掉就不报错了, 所以但是确信是它的锅(不推荐)
  2. 直接到thread-loader中翻阅相关的issue, 但是没有找到
  3. thread-loader的issue里提交bug report, 但是等了大概2-3天没有回复
  4. ts-loader翻阅issue, 看到好多人都遇到了相关的问题,但是试了几个没有用

最终,终于在ts-laoder找到了一个相似的解答直接就解决了问题
https://github.com/TypeStrong/ts-loader/issues/1242

解决方案:

ts-loader中配置开启happyPackMode

{
    loader: "ts-loader",
    options: {
      happyPackMode: true
    }
},
posted @ 2022-09-12 13:14  R_Javac  阅读(1039)  评论(0编辑  收藏  举报
Live2D
干嘛呢你,快把手拿开