基本的“你好世界”反应应用程序正在抛出错误

时间:2017-08-21 09:30:16

标签: javascript reactjs

使用ReactJS框架/库,我在关注this教程之后在Windows平台上创建了一个基本的“Hello World”反应应用程序,但是当我在cmd上使用C:\Users\username\Desktop\reactApp>npm start命令运行它时会抛出错误。请告诉我这是什么问题?

错误:

> reactApp@1.0.0 start C:\Users\username\Desktop\reactApp
> webpack-dev-server --hot

'webpack-dev-server' is not recognized as an internal or external command,
operable program or batch file.

npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.11.2
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! reactApp@1.0.0 start: `webpack-dev-server --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactApp@1.0.0 start script 'webpack-dev-server --hot'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the reactApp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     webpack-dev-server --hot
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs reactApp
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls reactApp
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\username\Desktop\reactApp\npm-debug.log

index.html 文件

<!DOCTYPE html>
<html lang = "en">

   <head>
      <meta charset = "UTF-8">
      <title>React App</title>
   </head>

   <body>
      <div id = "app"></div>
      <script src = "index.js"></script>
   </body>

</html>

main.js 档案

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.jsx';

ReactDOM.render(<App />, document.getElementById('app'));

App.jsx 文件

import React from 'react';

class App extends React.Component {
   render() {
      return (
         <div>
            Hello World!!!
         </div>
      );
   }
}

export default App;

package.json 文件

{
  "name": "reactApp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --hot"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^15.6.1",
    "react-dom": "^15.6.1"
  }
}

webpack.config.js 文件

var config = {
   entry: './main.js',

   output: {
      path:'./',
      filename: 'index.js',
   },

   devServer: {
      inline: true,
      port: 8080
   },

   module: {
      loaders: [
         {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: 'babel',

            query: {
               presets: ['es2015', 'react']
            }
         }
      ]
   }
}

module.exports = config;

1 个答案:

答案 0 :(得分:1)

理想情况下,它应该自己安装此模块 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@+id/centerButton" android:text="Mistery"/> <Button android:id="@+id/centerButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="Romance"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/centerButton" android:text="Science Fiction"/> </RelativeLayout> ,因为默认情况下它被称为webpack-dev-server中的生产依赖项。但是,您的package.json模块可能会以某种方式跳过它或者未正确安装。您可以手动删除npm文件夹并再次执行node_modules,它应该可以正常工作。

相关问题