晚上好,我在Ubuntu上使用了react 16.3.2,并希望将我的新反应应用程序与this software集成。
我的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
服务器开始运行时,但当我去刷新 localhost 网页时,我得到了错误如下:
ReferenceError:未定义窗口 在module.exports(bundle.js:5:41) 在bundle.js:728:10 在 () at /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对我来说仍然是一个新手,所以我甚至不确定这个错误是什么或它意味着什么。
有人可以在这里说明一点,并指出我正确的方向吗?
答案 0 :(得分:0)
搜索&#39;窗口&#39;在您的代码中,并确保在客户端使用! SERVER 或类似代码时执行它。