[英]Uncaught ReferenceError: Cannot access 'CONFIG' before initialization
The project created by CRA. CRA 创建的项目。
utils/config.js工具/config.js
CONFIG={
test:'test
}
Then I imported at my src/index.js(which is root of project)然后我在我的 src/index.js(这是项目的根目录)中导入
<Provider store={store}>
<Router>
<Switch>
<Route path='/' exact>
<MainContainer title={'Welcome to something'} />
</Route>
<Route path='/dummy' exact>
<DummyContainer />
</Route>
<Route path='/pop/:topicId' exact>
<Popup />
</Route>
<Route path='/app' exact>
<App />
</Route>
</Switch>
</Router>
</Provider>,
import 'utils/config';导入“工具/配置”;
I can access CONFIG from my component which is called from src/index.js我可以从从 src/index.js 调用的组件访问 CONFIG
but error occurred that cannot access to CONFIG.但是发生了无法访问 CONFIG 的错误。
Is there anyway to put CONFIG in very first state?反正有没有把 CONFIG 放在第一个状态?
THANK you.谢谢你。
make sure you exported it correctly.确保您正确导出它。 It should be either default or named export.
它应该是默认的或命名的导出。 try changes below
尝试下面的更改
utils/config.js工具/config.js
export default {
test:'test'
}
src/index.js(which is the root of the project) src/index.js(这是项目的根目录)
import config from 'utils/config'
now you can use your config
object as you want现在您可以根据需要使用
config
对象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.