尝试设置react.js环境,无法正常工作

时间:2019-02-27 06:10:51

标签: node.js reactjs npm webpack environment

我使用了https://www.tutorialspoint.com/reactjs/reactjs_environment_setup.htm

的教程

当我输入“ npm start”时,在命令提示符下出现以下消息,我已完成所有操作,并安装了node.js。请帮助!!

编辑:wjwar是用户名

C:\Users\wjwar\Desktop\reactApp>npm start

> reactApp@1.0.0 start C:\Users\wjwar\Desktop\reactApp
> webpack-dev-server --mode development --open --hot

'webpack-dev-server' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactApp@1.0.0 start: `webpack-dev-server --mode development --open --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactApp@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\wjwar\AppData\Roaming\npm-cache\_logs\2019-02-27T06_01_00_391Z-debug.log

3 个答案:

答案 0 :(得分:1)

指南https://www.tutorialspoint.com/reactjs/reactjs_environment_setup.htm中的第3步将npm install --save用于webpackwebpack-dev-serverwebpack-cli,这是不正确的。应该是npm install --save-dev

>npm install webpack --save-dev
>npm install webpack-dev-server --save-dev
>npm install webpack-cli --save-dev

该指南似乎也已经过时了,我怀疑它使用的是webpack版本3,而当前的webpack的默认版本是4。您可以尝试使用更新的设置来查找另一个示例,或者坚持使用create-react-app

答案 1 :(得分:0)

相反,请使用Create-react-app来设置整个样板,编辑app.js进行更改

答案 2 :(得分:0)

全局安装webpack和webpack-dev-server:

  1. 以管理员身份打开cmd
  2.   

    npm install -g webpack webpack-cli webpack-dev-server

  3. 重新启动cmd