[英]ReferenceError: window is not defined with ReactJS
晚上好,我在Ubuntu上使用react 16.3.2,并希望将此新的react应用程序与此软件集成在一起。
我的webpack.fly.config.js文件:
const path = require("path");
const webpack = require("webpack");
const bundlePath = path.resolve(__dirname, "dist/");
module.exports = {
entry: "./src/index.js",
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: { presets: ['react']}
},
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
}
]
},
resolve: { extensions: ['*', '.js', '.jsx'] },
output: {
publicPath: bundlePath,
filename: "bundle.js"
},
devServer: {
contentBase: path.join(__dirname,'public'),
port: 3000,
publicPath: "http://localhost:3000/dist"
},
plugins: [ new webpack.HotModuleReplacementPlugin() ]
};
我不认为这是问题所在,因为当我运行fly server
,服务器开始运行,但是当我刷新本地主机网页时,出现以下错误:
ReferenceError:未在module.exports(bundle.js:5:41)在bundle.js:728:10在()的/usr/local/lib/node_modules/@fly/fly/lib/default_context_store.js中定义窗口:47:30
我的index.js文件:
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('root')
);
还有我的index.html:
<!-- sourced from https://raw.githubusercontent.com/reactjs/reactjs.org/master/static/html/single-file-example.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>React Starter</title>
</head>
<body>
<div id="root"></div>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<script src="../dist/bundle.js"></script>
</body>
</html>
对我来说,React和Webpack还是很陌生的,所以我什至不确定这个错误是什么或意味着什么。
有人可以在这里给我一些启发,并向我指出正确的方向吗?
在代码中搜索“窗口”,并确保在客户端使用时执行该窗口 SERVER或类似的服务器 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.