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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM