【发布时间】:2019-08-12 21:40:52
【问题描述】:
在我的应用程序中,我使用 React on Rails 和 webpack 来构建它。
我将 OSX 与 VSCode 一起使用。当我尝试从我的文件中导入我的 Redux Store 时,我得到一个奇怪的“未捕获的错误:找不到模块”../../bundles/store”。
但是在下一行,同一个文件,导入是正确的。
这是我的客户端/app/components/wallbuilder/wallbuilder.jsx 导入:
import { store as STORE } from "../../bundles/store";
import { enclosure } from "../../bundles/store/action_creators.jsx";
这里是我的客户端/app/bundles/store.jsx 文件:
import {createStore, combineReducers} from 'redux';
// Note: this file is not very decomposed on purpose.
// Start splitting only if this is unwieldy to handle
function counter(state = 0, action) {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
default:
return state
}
}
// Enclosure
import * as ACTIONS from './store/actions.jsx';
const ENCLOSURE_INITIAL = {cladding: '', type: '', showFilters: true};
function enclosure(state = ENCLOSURE_INITIAL, action) {
switch(action.type) {
case ACTIONS.ENCLOSURE_SET_CLADDING:
return Object.assign({}, state, {cladding: action.value})
case ACTIONS.ENCLOSURE_SET_TYPE:
return Object.assign({}, state, {type: action.value})
case ACTIONS.ENCLOSURE_SHOW_FILTERS:
return Object.assign({}, state, {showFilters: action.value})
default:
return state;
}
}
export const store = createStore(combineReducers({counter, enclosure}));
尝试导入 {store as STORE } 的这一行是被破坏的行。
在我拥有的文件夹/文件上。
那么,我的 wallbuilder 文件中没有正确加载商店的选项有哪些?
【问题讨论】:
-
store.jsx在counter减速器下方有import。 It should be on the top of the file。将import移到顶部会帮助解决问题吗?