运行npm start时出现以下错误:
./src/containers/CarForm.js
Module not found: Can't resolve 'react/redux' in 'C:\Users\james\Desktop\Chariot\chariot-client\src\containers'
通过运行npm install react-redux --save
(或类似的变体)可以解决关于SO的类似问题。
我尝试删除package-lock.json,然后运行npm install并清除缓存。
这是我的package.json
代码:
{
"name": "chariot-client",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.1",
"react-dom": "^16.8.1",
"react-redux": "^6.0.0",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.2",
"redux": "^4.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {}
}
这是有问题的文件(CarForm.js):
import React, { Component } from 'react';
import { connect } from 'react/redux';
import { updateCarFormData } from '../actions/carForm';
import { createCar } from '../actions/cars';
class CarForm extends Component {
handleOnChange = event => { //rest of code
..
我曾经遇到错误“无法解析'react'”,但对于'react-redux'却没有得到相同的信息,所以我猜测我没有正确导入它(或者其他很明显的东西)
任何帮助将不胜感激。
答案 0 :(得分:2)
软件包名称为react-redux
,因此您的导入语句应为
import { connect } from 'react-redux'