【问题标题】:How can I compile and run the attached react web application?如何编译和运行附加的 React Web 应用程序?
【发布时间】:2017-04-15 20:32:13
【问题描述】:

我是 node 和 npm 的新手。我一直在尝试编译我在 GitHub (https://github.com/marshallmurphy/Web-Apps/tree/master/Medication%20Reminder%20React%20App) 上找到的这个药物提醒应用程序,但 npm 不断产生错误。我试过“npm start”并运行“webpack”但没有运气。如何在终端编译和运行这个文件?

运行 npm start 时出现以下错误:

Dantes-MBP:Medication Reminder React App dantegreyson$ npm start

> medication-reminder-app@1.0.0 start /Users/dantegreyson/Desktop/Medication Reminder React App
> webpack-dev-server

sh: webpack-dev-server: command not found

npm ERR! Darwin 16.1.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.9.1
npm ERR! npm  v4.0.2
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! medication-reminder-app@1.0.0 start: `webpack-dev-server`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the medication-reminder-app@1.0.0 start script 'webpack-dev-server'.
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 medication-reminder-app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     webpack-dev-server
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs medication-reminder-app
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls medication-reminder-app
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/dantegreyson/Desktop/Medication Reminder React App/npm-debug.log

我尝试按照建议全局安装 webpack,但现在出现以下错误:

Dantes-MBP:Medication Reminder React App dantegreyson$ npm start

> medication-reminder-app@1.0.0 start /Users/dantegreyson/Desktop/Medication Reminder React App
> webpack-dev-server

module.js:471
    throw err;
    ^

Error: Cannot find module 'html-webpack-plugin'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/dantegreyson/Desktop/Medication Reminder React App/webpack.config.js:1:87)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

npm ERR! Darwin 16.1.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.9.1
npm ERR! npm  v4.0.2
npm ERR! code ELIFECYCLE
npm ERR! medication-reminder-app@1.0.0 start: `webpack-dev-server`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the medication-reminder-app@1.0.0 start script 'webpack-dev-server'.
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 medication-reminder-app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     webpack-dev-server
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs medication-reminder-app
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls medication-reminder-app
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/dantegreyson/Desktop/Medication Reminder React App/npm-debug.log

【问题讨论】:

  • npm install && npm start。如果它没有帮助。请发布相关错误
  • @TheReason 我安装了最新版本的 npm 和 node。但是我仍然收到错误消息。我已经发布了上面的错误。
  • 我刚刚克隆了存储库并做了npm install,安装完成后我做了npm start 它就像魅力一样。节点版本4.4.3npm install 安装必要的软件包。我之前没有安装 webpack 或相关包。
  • @SatishPatel 在定向到 localhost:8080 之后,Web 应用程序是否在第一页之后工作(药物提醒:开始使用)?
  • npm start 之后导航到localhost:8080 它呈现药物提醒开始。

标签: node.js reactjs npm webpack package.json


【解决方案1】:

如果您查看脚本部分中的 package.json,您将看到它尝试运行的内容 "start": "webpack-dev-server"。所以你应该全局安装webpack-dev-server sudo npm install webpack-dev-server -g 应该为你施展魔法。

更新

确保运行npm install 命令

【讨论】:

  • 我试过这个但是我得到错误找不到模块'html-webpack-plugin'。我已经在上面详细发布了这个错误。
  • @DanteGreyson 您是否运行了命令 npm install ?它应该已经安装了所有依赖项
  • 是的,你是对的,我再次尝试了 npm install,它成功了!由于某种原因,之前没有安装依赖项。我收到消息 webpack:bundle 现在有效。运行 npm start 后。我该如何从这里开始?
  • @DanteGreyson 默认情况下 webpack-dev-server 使用 8080 端口。尝试连接 localhost:8080
  • 是的,这行得通!但是该页面不会超过第一页。但是编译仍然有效,谢谢。有没有办法运行 index.html?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-25
  • 1970-01-01
  • 1970-01-01
  • 2014-01-22
  • 1970-01-01
  • 2014-06-22
  • 2020-06-28
相关资源
最近更新 更多