gpt4 book ai didi

javascript - 创建一个 react 项目

转载 作者:行者123 更新时间:2023-12-03 00:56:28 25 4
gpt4 key购买 nike

prtScn我正在尝试启动新的 react 应用程序,但遇到了问题。我使用 Visual Studio Code ,并按照说明进行操作:在可视化代码终端中:

create-react-app sali (sali is the name)
npm install
node node_modules\webpack\bin\webpack.js -d -w

然后我收到这条消息:

ERROR in ./src/index.js 7:16
Module parse failed: Unexpected token (7:16)
You may need an appropriate loader to handle this file type.
| 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

这里是代码:(这是创建React应用程序的默认代码)索引.js

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.
serviceWorker.unregister();

app.js

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
}

export default App;

package.json

{
"name": "sali",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-scripts": "2.0.4"
},
"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": {
"webpack-cli": "^3.1.2"
}
}

请问,这是怎么回事?

最佳答案

我猜你在终端中写的是

> create-react-app sali
> npm install
> node node_modules\webpack\bin\webpack.js -d -w

使用 Create-React-App,这不是你应该做的,你应该做:

> create-react-app sali
> cd sali
> npm run start

你应该阅读React documentation and tutorials因为他们会提供很好的帮助!

关于javascript - 创建一个 react 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52810432/

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