Javascript 无法读取属性';搜索';未定义-网页包开发服务器
一点背景:我正在尝试使用Javascript 无法读取属性';搜索';未定义-网页包开发服务器,javascript,reactjs,webpack,webpack-dev-server,Javascript,Reactjs,Webpack,Webpack Dev Server,一点背景:我正在尝试使用静态站点生成器webpack插件在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
静态站点生成器webpack插件
在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)
我的网页包如下所示:
/*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>'
}
最后,条目文件如下所示:
/*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>'
}
module.exports=函数渲染(局部){
返回“你好,世界”
}
我非常感谢您对我遇到的问题的任何反馈。这是我第一次使用这个插件
链接:
插件很久没有更新了。您是否尝试过使用较旧的网页包版本?它可能只是不适用于4 我使用webpack
2.3.3
和webpack dev server1.16.4
另外,对于任何对样板文件感兴趣的人,我找到了使用该插件的用户。该插件很长时间没有更新。您是否尝试过使用较旧的网页包版本?它可能就是不适合你4@lukas-谢谢你的帮助!让它与Webpack2.3.3和WebpackDevServer1.16.4一起工作D