首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法启动webpack-dev-server

无法启动webpack-dev-server
EN

Stack Overflow用户
提问于 2018-08-17 15:42:05
回答 1查看 2.1K关注 0票数 2

我正在尝试做一个React教程,虽然我已经从讲师那里下载了文件,但我无法在我的笔记本电脑上启动web-dev-server。但是,我可以让它在我的台式计算机上工作。不过,我需要能够在我的笔记本电脑上工作,所以如果能帮助我找出问题所在,我将不胜感激。我已经尝试删除并重新安装服务器文件夹(多次),也尝试删除并重新安装webpack-dev- node_modules文件夹。据我所知,没有其他程序使用相同的端口(8080)。

下面是我得到的错误日志:

代码语言:javascript
复制
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@6.4.0
3 info using node@v8.11.3
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle github-battle@1.0.0~prestart: github-battle@1.0.0
6 info lifecycle github-battle@1.0.0~start: github-battle@1.0.0
7 verbose lifecycle github-battle@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle github-battle@1.0.0~start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/eleerogers/Downloads/react-fundamentals-first-component/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
9 verbose lifecycle github-battle@1.0.0~start: CWD: /Users/eleerogers/Downloads/react-fundamentals-first-component
10 silly lifecycle github-battle@1.0.0~start: Args: [ '-c', 'webpack-dev-server --open' ]
11 silly lifecycle github-battle@1.0.0~start: Returned: code: 1  signal: null
12 info lifecycle github-battle@1.0.0~start: Failed to exec start script
13 verbose stack Error: github-battle@1.0.0 start: `webpack-dev-server --open`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:304:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid github-battle@1.0.0
15 verbose cwd /Users/eleerogers/Downloads/react-fundamentals-first-component
16 verbose Darwin 17.7.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
18 verbose node v8.11.3
19 verbose npm  v6.4.0
20 error code ELIFECYCLE
21 error errno 1
22 error github-battle@1.0.0 start: `webpack-dev-server --open`
22 error Exit status 1
23 error Failed at the github-battle@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

下面是webpack.config.js:

代码语言:javascript
复制
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: './app/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'index_bundle.js'
  },
  module: {
    rules: [
      { test: /\.(js)$/, use: 'babel-loader' },
      { test: /\.css$/, use: [ 'style-loader', 'css-loader' ]}
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: 'app/index.html'
    })
  ],
  mode: "development"
};

下面是package.json:

代码语言:javascript
复制
{
  "name": "github-battle",
  "version": "1.0.0",
  "description": "Project for TylerMcGinnis.com's fundamental course.",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --open"
  },
  "author": "Tyler McGinnis",
  "license": "MIT",
  "babel": {
    "presets": [
      "env",
      "react"
    ]
  },
  "dependencies": {
    "react": "^16.0.0-alpha.5",
    "react-dom": "^16.0.0-alpha.5"
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-plugin-transform-async-to-generator": "^6.24.1",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "css-loader": "^0.28.11",
    "html-webpack-plugin": "^3.2.0",
    "style-loader": "^0.21.0",
    "webpack": "^4.8.3",
    "webpack-cli": "^2.1.4",
    "webpack-dev-server": "^3.1.5"
  }
}

虽然,正如我所说,它在我的桌面上工作,所以我不认为它有任何问题…我的笔记本电脑出了点问题。这是一款新的Macbook Air。谢谢你的帮助!

EN

回答 1

Stack Overflow用户

发布于 2018-08-18 04:18:32

npm清理缓存

然后

npm安装

这应该可以解决您的问题。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51890557

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档