gpt4 book ai didi

javascript - 无法从React应用程序中的redux库导入商店

转载 作者:行者123 更新时间:2023-12-02 22:44:15 24 4
gpt4 key购买 nike

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

// 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 已经安装了,我已经 npm install 了很多次

目录结构:

.
├── 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

最佳答案

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

- application
- redux
- store.js

所以你的路径将是./redux/store

关于javascript - 无法从React应用程序中的redux库导入商店,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58477317/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com