我的文件夹结构如下:
在我的 App.Js(位于组件文件夹下)中,我有:
import variables from '/src/EnvVariables/variables.json';
Run Code Online (Sandbox Code Playgroud)
但是,我收到错误:
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/.
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
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';
Run Code Online (Sandbox Code Playgroud)
所有这些要么给出上述错误,要么说“无法解析文件”。
正如他们所说,该文件位于 /src 下的文件夹中。但它仍然告诉我它必须在 /src/ 目录下。如何导入我的variables.json 文件?我不想只是将它放在“组件”下,我更喜欢更好地组织它。
reactjs ×1