我是ReactJS的初学者。在完成有关React和Redux基础知识的课程之后。我已经开始了新的Udemy课程,标题为“反应数据可视化-构建加密货币仪表板”。尝试使用yarn start
命令启动服务器时,我在第4课中遇到问题:
Failed to compile
./src/index.js
Cannot find file: 'index.js' does not match the corresponding name on disk: '.\src\App\app'.
这是我在index.js
目录下的app
文件上的代码:
import React, { Component } from 'react';
import './App.css';
class App extends Component {
render(){
return (
<div>
Hello World
</div>
);
}
}
export default App;
这是我在index.js
目录下的src
文件上的代码:
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
如何解决此问题?
您可以在此处找到项目文件。
https://drive.google.com/open?id=1u-8mCYSWZtXPbIqELKsF33FOiXb3yrkH
编辑1 :我正在按照@Wesgur的建议在package.json文件中添加代码:
{
"name": "cryptodash",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.4.0"
},
"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"
]
}
}
答案 0 :(得分:1)
@Shawan这只是将src / index中的App import语句从import App from './App';
更改为import App from './app';
的错字。
答案 1 :(得分:0)
从“ ./app”导入应用; 这将导入您的app文件夹的index.js。