Cannot read properties of undefined (reading 'hooks')
记录解决方案
问题描述:
在thread-loader
和ts-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)
做过的尝试:
- 直接把
thread-loader
去掉就不报错了, 所以但是确信是它的锅(不推荐) - 直接到
thread-loader
中翻阅相关的issue, 但是没有找到 - 在
thread-loader
的issue里提交bug report, 但是等了大概2-3天没有回复 - 在
ts-loader
翻阅issue, 看到好多人都遇到了相关的问题,但是试了几个没有用
最终,终于在ts-laoder
找到了一个相似的解答直接就解决了问题
https://github.com/TypeStrong/ts-loader/issues/1242
解决方案:
在ts-loader
中配置开启happyPackMode
{
loader: "ts-loader",
options: {
happyPackMode: true
}
},