【发布时间】:2019-06-01 18:01:08
【问题描述】:
我正在使用 wepback 制作一个 Reactjs 应用程序,但我不明白为什么 npm run webpack-dev-server 不起作用。
我安装了这个包,甚至全局安装了它。每次我遇到与提到的相同的错误时。
我的 webpack.config.js:
var webpack = require('webpack');
var path = require('path');
var dev = require('webpack-dev-server');
var BUILD_DIR = path.resolve(__dirname, 'src/client/public');
var APP_DIR = path.resolve(__dirname, 'src/client/app');
var config = {
entry: APP_DIR + '/index.js',
output: {
path: BUILD_DIR,
filename: 'bundle.js'
},
devServer: {
inline:true,
port: 8008
},
module : {
loaders : [
{
test : /\.jsx?/,
include : APP_DIR,
loader : 'babel-loader'
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
}
]
}
};
module.exports = config;
还有我的 package.json:
{
"name": "redditgallery",
"version": "1.0.0",
"description": "Wix project",
"main": "index.js",
"scripts": {
"dev": "webpack -d --watch",
"build": "webpack -p",
"ser": "wepback-dev-server -d"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tamirhuber/RedditGallery.git"
},
"author": "Tamir Huber",
"license": "UNLICENSED",
"bugs": {
"url": "https://github.com/tamirhuber/RedditGallery/issues"
},
"homepage": "https://github.com/tamirhuber/RedditGallery#readme",
"dependencies": {
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"webpack": "^2.4.1"
},
"devDependencies": {
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"css-loader": "^0.28.0",
"style-loader": "^0.16.1"
}
}
这是错误:
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "webpack-dev-server"
npm ERR! node v6.10.2
npm ERR! npm v3.10.10
npm ERR! missing script: webpack-dev-server
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! C:\redditGallery\npm-debug.log
有什么想法吗?
【问题讨论】:
-
你有
"ser": "wepback-dev-server -d"而在 devdependencies 中没有webpack-dev-server... -
我遇到了同样的问题,我在我的 webpack.config 文件中使用了这个:devServer: { contentBase: path.join(__dirname, "dist"), compress: true, port: 9000 }它工作。
标签: reactjs npm webpack webpack-dev-server