TypeError:添加 webpack-subresource-integrity 时无法读取未定义的属性“tap”
Posted
技术标签:
【中文标题】TypeError:添加 webpack-subresource-integrity 时无法读取未定义的属性“tap”【英文标题】:TypeError: Cannot read property 'tap' of undefined when adding webpack-subresource-integrity 【发布时间】:2021-12-14 07:25:14 【问题描述】:我正在尝试在我的config-overrides.js
(react-app-rewired) 上配置webpack-subresource-integrity 包:
const SubresourceIntegrityPlugin = require('webpack-subresource-integrity');
module.exports = function override(config, env)
config.optimization.splitChunks.cacheGroups =
...config.optimization.splitChunks.cacheGroups,
project:
test: /[\\/]node_modules[\\/]@project[\\/]/
;
// added this part
config.output =
crossOriginLoading: 'anonymous'
;
config.plugins = [...config.plugins, new SubresourceIntegrityPlugin()];
return config;
;
我收到TypeError: Cannot read property 'tap' of undefined
我已经尝试删除我的 node_modules、yarn.lock,然后重新安装这些包,但我仍然遇到同样的错误。
这是完整的错误:
/Users/me/myProject/node_modules/react-scripts/scripts/start.js:19
throw err;
^
TypeError: Cannot read property 'tap' of undefined
at /Users/me/myProject/node_modules/webpack-subresource-integrity/index.js:235:48
at SyncHook.eval [as call] (eval at create (/Users/me/myProject/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:89:1)
at SyncHook.lazyCompileHook (/Users/me/myProject/node_modules/tapable/lib/Hook.js:154:20)
at Compiler.newCompilation (/Users/me/myProject/node_modules/webpack/lib/Compiler.js:631:26)
at /Users/me/myProject/node_modules/webpack/lib/Compiler.js:667:29
at _next0 (eval at create (/Users/me/myProject/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
at eval (eval at create (/Users/me/myProject/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:26:1)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
【问题讨论】:
你能添加你的 package.josn 吗? 【参考方案1】:我有解决方案可以正常工作,请按照以下步骤操作:
-
从项目目录中删除 node_modules 文件夹
删除 package-lock.json 文件
确保使用此命令清除缓存 npm cache clean --force
随后使用此命令 npm cache verify 验证内存字节
然后再次使用 npm install
【讨论】:
以上是关于TypeError:添加 webpack-subresource-integrity 时无法读取未定义的属性“tap”的主要内容,如果未能解决你的问题,请参考以下文章
TypeError:无法读取未定义 Discord.js javascript 的属性“添加”
discord.js - 机器人不会添加角色:TypeError:无法读取未定义的属性“添加”
在 AdvanceDataGrid 中添加记录时:TypeError:错误 #1010:术语未定义且没有属性
将 prevstate 参数添加到 this.setState 会导致 typeError