react-create-app src引入目錄外部文件衝突問題:Relative imports outside of src/ are not supported.

使用react-create-app構建的項目,當src文件夾下文件想引用src文件夾外文件由於官方限制問題會報如下錯誤。

node

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/.react

 

解決方法:1,項目直接eject命令,若是以前執行過了產生了webpack等文件就不用再執行。webpack

                2,將webpack.config.dev中ModuleScopePlugin命令註釋掉便可。web

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

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

相關文章
相關標籤/搜索