找不到模块提升机没有反应的静电

时间:2018-10-15 15:34:11

标签: reactjs

我正在通过创建Blogpost应用来练习React Redux。 创建新的帖子组件时遇到问题。 我已经安装了axios,redux-promise。 我已经安装了react-router 4.0.0,react-router-dom 4.2.2,redux-form 6.6.3

1。这是我的src / index.js

import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { createStore, applyMiddleware } from "redux";
import { BrowserRouter, Route, Switch } from "react-router-dom";
import promise from "redux-promise";

import reducers from "./reducers";
import PostIndex from "./components/posts_index";
import PostsNew from "./components/posts_new";

const createStoreWithMiddleware = applyMiddleware(promise)(createStore);

ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<BrowserRouter>
  <div>
    <Switch>
      <Route path="/posts/new" component={PostsNew} />
      <Route path="/" component={PostIndex} />
    </Switch>
  </div>
</BrowserRouter>
</Provider>,
document.querySelector(".container")
);

2。这是我的动作/index.js

import axios from "axios";

export const FETCH_POSTS = "FETCH_POSTS";

const ROOT_URL = "http://reduxblog.herokuapp.com/api";
const API_KEY = "?key=SHUVRO1234";

export function fetchPosts() {
const request = axios.get(`${ROOT_URL}/posts${API_KEY}`);
return {
type: FETCH_POSTS,
payload: request
};
}

3。这是reducers / index.js

import { combineReducers } from "redux"; 
import { reducer as formReducer } from "redux-form";
import PostsReducer from "./reducer_posts";

const rootReducer = combineReducers({
posts: PostsReducer,
form: formReducer
});

export default rootReducer;

4。这是动作减少器

import _ from "lodash";
import { FETCH_POSTS } from "../actions";

export default function(state = {}, action) {
switch (action.type) {
case FETCH_POSTS:
return _.mapKeys(action.payload.data, "id");
default:
return state;
}
}

5。这是显示错误的posts_new组件

import React, { Component } from "react";
import { Field, reduxForm } from "redux-form";

class PostsNew extends Component {
renderTitleField(field) {
return (
<div>
<input type="text" {...field.input} />
</div>
);
}
render() {
return (
<form>
<Field name="title" component={this.renderTitleField} />
</form>
);
}
}

export default reduxForm({ form: "PostsNewForm" })(PostsNew);

这是控制台中的错误

bundle.js:20326 Uncaught Error: Cannot find module "hoist-non-react-statics"
at webpackMissingModule (bundle.js:20326)
at Object.<anonymous> (bundle.js:20326)
at Object.invariant (bundle.js:20624)
at __webpack_require__ (bundle.js:20)
at Object.exports.__esModule (bundle.js:19501)
at __webpack_require__ (bundle.js:20)
at Object.<anonymous> (bundle.js:64)
at __webpack_require__ (bundle.js:20)
at Object.<anonymous> (bundle.js:47)
at __webpack_require__ (bundle.js:20)

请帮助我解决此错误

1 个答案:

答案 0 :(得分:1)

只需运行“ npm i hoist-non-react-statics” 希望对您有帮助