无法从React App中的Redux库导入商店

时间:2019-10-20 21:04:10

标签: javascript node.js reactjs npm redux

我正在使用以下javascript在官方react-redux网站HERE上尝试redux示例:

// index.js
import React from 'react'
import ReactDOM from 'react-dom'
import TodoApp from './TodoApp'

import { Provider } from 'react-redux'
import store from './redux/store'

const rootElement = document.getElementById('root')
ReactDOM.render(
  <Provider store={store}>
    <TodoApp />
  </Provider>,
  rootElement
)

但是出现以下错误:

Module not found: Can't resolve './redux/store' in '/mnt/d/Projects/engage-calculator/src'

我的package.json是

{
  "name": "engage-calculator",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "bootstrap": "^4.3.1",
    "react": "^16.10.2",
    "react-dom": "^16.10.2",
    "react-redux": "^7.1.0",
    "react-scripts": "3.2.0",
    "redux": "^4.0.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

怎么了? codesandbox页面具有与我相同的目录结构,我也使用{}尝试了命名导入,但未做任何更改。我可以向您保证,已经安装了redux多次安装了pmp

目录结构:

.
├── README.md
├── package-lock.json
├── package.json
├── public
│   ├── favicon.ico
│   ├── index.html
│   ├── logo192.png
│   ├── logo512.png
│   ├── manifest.json
│   └── robots.txt
└── src
    ├── App.css
    ├── App.js
    ├── App.test.js
    ├── components
    │   └── calculator.js
    ├── index.css
    ├── index.js
    ├── logo.svg
    └── serviceWorker.js

1 个答案:

答案 0 :(得分:1)

您的问题是您应该创建商店,他们使用了自定义路径,因此他们创建了一个名为redux的文件夹和一个名为store file的文件

- application
   - redux
     - store.js

因此您的路径将为./redux/store