react-create-app src引入目录外部文件冲突问题:Relative imports outside of src/ are not supported.

使用react-create-app构建的项目,当src文件夹下文件想引用src文件夹外文件因为官方限制问题会报以下错误。

Module not found: You attempted to import ****** which falls outside of the project src/ directory. Relative imports outside of src/ are not supported. You can either move it inside src/, or add a symlink to it from project's node_modules/.

解决方法:1,项目直接eject命令,如果之前执行过了产生了webpack等文件就不用再执行。

2,将webpack.config.dev中ModuleScopePlugin命令注释掉即可。

//new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),

原答案出处:https://stackoverflow.com/questions/44114436/the-create-react-app-imports-restriction-outside-of-src-directory?noredirect=1