当前位置:   article > 正文

【React】Erroe:Cannot find module 'react-scripts/package.json'异常解决方案

cannot find module 'react

背景:

使用create-react-app搭建React开发环境后,添加config-overrides.js文件,并修改package.json中对应命令后,执行

npm start
  1. // config-overrides.js
  2. var path = require('path')
  3. const rewireWebpackBundleAnalyzer = require('react-app-rewire-webpack-bundle-analyzer')
  4. const { injectBabelPlugin } = require('react-app-rewired') // 安装babel-plugin-import插件(按需加载组件代码及样式的babel插件)
  5. const rewireLess = require('react-app-rewire-less')
  6. const theme = require('./theme')
  7. module.exports = function override(config, env) {
  8. config.resolve.alias['@Components'] = resolve('src/components')
  9. config.resolve.alias['@Page'] = resolve('src/page')
  10. config.resolve.alias['@Services'] = resolve('src/services')
  11. config.resolve.alias['@Store'] = resolve('src/store')
  12. config.resolve.alias['@Utils'] = resolve('src/utils')
  13. // 自定义主题
  14. config = injectBabelPlugin(
  15. ['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }], // change importing css to less
  16. config
  17. )
  18. config = rewireLess.withLoaderOptions({
  19. modifyVars:theme,
  20. javascriptEnabled:true
  21. })(config,env)
  22. return config
  23. }
  1. // package.json
  2. ...
  3. "scripts": {
  4. "start": "react-app-rewired --max_old_space_size=4096 --optimize_for_size start",
  5. "build": "cross-env NODE_ENV=production && react-app-rewired --max_old_space_size=4096 build",
  6. "lint": "eslint --fix src && prettier --write \"src/**/*.js\"",
  7. "test": "react-app-rewired test --env=jsdom"
  8. },
  9. ...

 

发报Erroe:Cannot find module 'react-scripts/package.json':

问题点:

缺少react-scripts插件

解决方案:

安装react-scripts插件

npm install --save react-scripts

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/630256
推荐阅读
相关标签
  

闽ICP备14008679号