无法读取未定义的 属性 'search' - 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:
The plugin wasn't updated in a long time. Have you tried with an older webpack version? It might just not work with 4.
我可以使用 webpack 2.3.3
和 webpack-dev-server 1.16.4
对于任何对样板感兴趣的人,我发现 react isomorphic static site generator boilerplate 使用了这个插件。
一些上下文:我正在尝试使用 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:
The plugin wasn't updated in a long time. Have you tried with an older webpack version? It might just not work with 4.
我可以使用 webpack 2.3.3
和 webpack-dev-server 1.16.4
对于任何对样板感兴趣的人,我发现 react isomorphic static site generator boilerplate 使用了这个插件。