簡體   English   中英

無法讀取未定義的屬性“搜索”-Webpack-dev-server

[英]Cannot read property 'search' of undefined - webpack-dev-server

有一點上下文:我正在嘗試使用static-site-generator-webpack-plugin在react中創建一個服務器端靜態網站。

有人可以幫我解決以下錯誤:

ERROR in TypeError: Cannot read property 'search' of undefined
    at Object.eval (webpack:///(webpack)-dev-server/client?:31:28)
    at eval (webpack:///(webpack)-dev-server/client?:248:30)
    at Object../node_modules/webpack-dev-server/client/index.js?http://localhost:8081 (evalmachine.<anonymous>:276:1)
    at __webpack_require__ (evalmachine.<anonymous>:30:30)
    at eval (webpack:///multi_(webpack)-dev-server/client?:1:1)
    at Object.0 (evalmachine.<anonymous>:377:1)
    at __webpack_require__ (evalmachine.<anonymous>:30:30)
    at evalmachine.<anonymous>:79:18
    at evalmachine.<anonymous>:82:10
    at webpackUniversalModuleDefinition (evalmachine.<anonymous>:3:20)

我用來啟動服務器的命令是webpack-dev-server --mode development

這些版本是:

static-site-generator-webpack-plugin: ^3.4.1
webpack-cli: ^2.1.3
webpack: ^4.8.1,
webpack-dev-server: ^3.1.4
node: 8.11.1

我的webpack看起來像這樣:

/*global require, module*/
const path = require("path")
const ExtractTextPlugin = require("extract-text-webpack-plugin")
const StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin')

module.exports = {
    entry: "./src/entry.js",
    output: {
        filename: 'index.js',
        path: path.resolve("dist"),
        libraryTarget: 'umd'
    },
    module: {
        rules: [
            {
                test: /\.scss$/,
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use: ["css-loader", "sass-loader"]
                })
            },
            {
                test: /\.css$/,
                use: [
                    { loader: "style-loader" },
                    { loader: "css-loader" }
                ]
            },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: "babel-loader"
            }
        ]
    },

    plugins: [
        new ExtractTextPlugin("dist/styles/main.css"),
        new StaticSiteGeneratorPlugin({
            paths: [
                '/'
            ],
            globals: {
                window: {}
            }
        })
    ]
}

最后,入口文件如下所示:

module.exports = function render(locals) {
    return '<html>Hello World</html>'
}

非常感謝您對我所遇到的問題的任何反饋。 這是我第一次使用此插件。

鏈接:

正如lukas-reineke在上述評論中提到的:

該插件很長時間沒有更新。 您是否嘗試過使用較舊的Webpack版本? 它可能不適用於4。

我將其與webpack 2.3.3和webpack-dev-server 1.16.4

對於對樣板感興趣的人,我還發現了使用此插件的react同構靜態站點生成器樣板

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM