我試圖用幾種不同的方法解決這個問題,所以我必須從頭開始。webpack-dev-server運行兩次
我有一個名爲webpack.dev.js
一個配置文件,如下圖所示:
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = {
entry: "./src/script.js",
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "dist")
},
devtool: "inline-source-map",
devServer: {
contentBase: path.join(__dirname, "dist")
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["env"]
}
}
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: ["css-loader", "postcss-loader", "sass-loader"]
})
}
]
},
plugins: [
new HtmlWebpackPlugin({template: path.join("src", "index.html")}),
new ExtractTextPlugin("style.css"),
new CopyWebpackPlugin([{from: "src/images", to: "images"}])
]
};
所以,我成立的package.json啓動腳本用於啓動開發服務器
"start": "webpack-dev-server --config webpack.dev.js"
現在是問題開始的地方。當我跑了劇本,我有以下錯誤
Invalid configuration object. webpack-dev-server has been initialized using a configuration object that does not match the API schema.
- configuration has an unknown property 'error'. These properties are valid:
object { hot?, hotOnly?, lazy?, bonjour?, host?, allowedHosts?, filename?, publicPath?, port?, socket?, watchOptions?, headers?, clientLogLevel?, overlay?, progress?, key?, cert?, ca?, pfx?, pfxPassphrase?, requestCert?, inline?, disableHostCheck?, public?, https?, contentBase?, watchContentBase?, open?, useLocalIp?, openPage?, features?, compress?, proxy?, historyApiFallback?, staticOptions?, setup?, stats?, reporter?, noInfo?, quiet?, serverSideRender?, index?, log?, warn? }
正如你所看到的,這個錯誤是非常令人困惑,因爲沒有任何error
財產上的配置文件
嘗試不同的方法來後解決這個問題,我試圖刪除devServer
屬性,並使用默認設置啓動dev服務器。
但現在是它變得奇怪時。輸出看起來就像如果Web服務器啓動了兩次:
Project is running at http://localhost:8080/
webpack output is served from/
Project is running at http://localhost:8081/
webpack output is served from/
之後,它會記錄有關有被multiple modules with names that only differ in casing
幾個警告然後一些谷歌上搜索後,我發現了別人也有這個unknown property 'error'
問題,他發生的原因是他有http-server
在後臺運行。
所以現在,我的理論是,由於某種原因,webpack-dev-server並行運行兩次,並且會產生競爭條件或錯誤,從而引發此unknown property 'error'
問題。
我只發現了另外兩個有類似問題的人,他們通過將inject: false
添加到HtmlWebpackPlugin
的配置對象中而被修復。這樣做並沒有使錯誤消失,並且在沒有devServer配置的情況下運行時,它只是從頁面中刪除所有js和css,因爲它不會將<link>
和<script>
標籤注入到html中。
在這一點上,我不知道如何解決這個問題,這就是爲什麼我問是否有人可以幫助我。
我看到一個已經工作好幾個月的現有項目的同樣的事情。一位同事正在試圖起牀並運行,並且正在用這種短暫的'錯誤'屬性來解決這個問題。它沒有任何意義,因爲我們在docker中運行所有的東西,我們使用npm-shrinkwrap ...因此他具有與其他人相同的環境。確認他與團隊的其他成員擁有相同的webpack和webpack-dev-server版本...... – Ghazgkull
獲得同樣的結果。也許它與最新版本有關? –
同樣的錯誤今天開始發生在我身上。 – corsen