反应构建 - 未找到:错误:无法解析“缓冲区”

问题描述

我在 React 中构建应用程序时遇到错误。我仅在尝试构建应用程序时才注意到此错误。

当我停止开发服务器并再次运行它时,它显示了同样的错误。似乎我做了一些更改,只有在我再次启动服务器或 make build 时才会显示:

未找到模块:错误:无法解析 '\node_modules\htmlparser2\lib' 中的 'buffer' 突破性变化:webpack

如果你想包含一个 polyfill,你需要安装 'buffer'。如果 你不想包含一个 polyfill,你可以使用一个空模块,比如 这: resolve.alias: { "buffer": false }

错误命令失败,退出代码为 1。

我的申请是用 CRA 和 Typescript 制作的。这是我的package.json

{
  "name": "my-app","version": "0.1.0","private": true,"scripts": {
    "start": "react-scripts start","build": "cross-env NODE_OPTIONS='--max-old-space-size=4096' react-scripts build","test": "react-scripts test","eject": "react-scripts eject"
  },"dependencies": {
    "@apollo/react-hooks": "^4.0.0","@date-io/moment": "^1.3.13","@material-ui/core": "^4.11.0","@material-ui/icons": "^4.9.1","@material-ui/lab": "^4.0.0-alpha.56","@material-ui/pickers": "^3.2.10","@optimizely/react-sdk": "^2.4.0","apollo-boost": "^0.4.9","classnames": "^2.2.6","formik": "^2.2.5","graphql": "^15.4.0","lodash": "^4.17.20","moment": "^2.29.1","react": "^16.13.1","react-app-polyfill": "^2.0.0","react-dom": "^16.13.1","react-google-recaptcha": "^2.1.0","react-masonry-css": "^1.0.14","react-router-dom": "^5.2.0","react-test-renderer": "^16.13.1","react-toastify": "^6.1.0","reset-css": "^5.0.1","use-debounce": "^5.1.0"
  },"devDependencies": {
    "@testing-library/jest-dom": "^5.11.6","@testing-library/react": "^11.2.1","@testing-library/user-event": "^12.2.2","@types/classnames": "^2.2.11","@types/enzyme": "^3.10.8","@types/enzyme-adapter-react-16": "^1.0.6","@types/jest": "^26.0.15","@types/lodash": "^4.14.165","@types/moment": "^2.13.0","@types/node": "^14.14.9","@types/react": "^16.9.56","@types/react-dom": "^16.9.9","@types/react-google-recaptcha": "^2.1.0","@types/react-router-dom": "^5.1.6","cross-env": "^7.0.2","enzyme": "^3.11.0","enzyme-adapter-react-16": "^1.15.5","enzyme-to-json": "^3.6.1","husky": "^4.3.0","jest-dom": "^4.0.0","jest-sonar-reporter": "^2.0.0","lint-staged": "^10.5.1","node-sass": "^5.0.0","prettier": "^2.2.0","ts-jest": "^26.4.4","typescript": "^4.1.2"
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)