1
我的文件夾結構如下:如何從外面/組件導入文件中反應
在我App.Js(這是組件文件夾下),我有:
import variables from '/src/EnvVariables/variables.json';
但是,我得到一個錯誤:
You attempted to import /src/EnvVariables/variables.json 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/.
我也試過:
import variables from './src/EnvVariables/variables.json';
import variables from '/src/EnvVariables/variables.json';
import variables from '/src/EnvVariables/variables.json';
import variables from '/EnvVariables/variables.json';
import variables from './EnvVariables/variables.json';
全部或者給出上述錯誤,或者說「無法解析文件」。
正如他們所說,該文件位於/ src下的文件夾中。但它仍然告訴我它必須在/ src /目錄下。我怎樣才能導入我的variables.json文件?我不想把它放在「組件」下面,我更願意更好地組織它。
您正在使用的WebPack第一個解決方案,可以爲您在問題 –