javascript - 类型错误 : Cannot read property 'tap' of undefined when adding webpack-subresource-integrity

标签 javascript reactjs webpack subresource-integrity

我正在尝试配置 webpack-subresource-integrity我的 config-overrides.js 上的包( react-app-rewired ):

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:无法读取未定义的属性“tap”

我已经尝试删除我的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.

最佳答案

我有解决方案,可以正常工作,请按照以下步骤操作:

  1. 从项目目录中删除node_modules文件夹
  2. 删除 package-lock.json 文件
  3. 确保使用此命令清除缓存 npm cache clean --force
  4. 然后使用此命令 npm cache verify 验证内存字节
  5. 然后再次使用 npm install

关于javascript - 类型错误 : Cannot read property 'tap' of undefined when adding webpack-subresource-integrity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69765158/

相关文章:

javascript - 根据对象数组过滤对象数组返回相同的结果

javascript - JS中获取字符串长度

javascript - 如何处理 javascript var

javascript - Webpack-dev-server 不热刷新我的客户端文件

vue.js - 如何使用 JS Quasar Framework 从构建中删除 console.log?

vue.js - 是否可以在运行时动态配置 vue-cli 中的 publicPath?

php - 将 php 变量发送到 javascript

javascript - React-select:自定义控件不呈现选择组件

reactjs - React.memo 不起作用 - 我错过了什么?

webpack - Watch Ignore Plugin 已使用与 API 架构不匹配的选项对象进行初始化