which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
如上由于使用create-react-app
后不能引入src文件夹外的文件。
解决方案为:
借助react-app-rewired
重写webpack配置。
npm i --save-dev react-app-rewired customize-cra
修改package.json
"scripts": {
- "start": "react-scripts start"
+ "start": "react-app-rewired start",
},
根目录下新建config-overrides.js
const { removeModuleScopePlugin } = require('customize-cra')
module.exports = removeModuleScopePlugin()