晚上好,我正在Ubuntu上使用react 16.3.2,我想将我的新react应用程序与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
时,服务器开始运行,但当我刷新我的本地主机网页时,我得到以下错误:
ReferenceError:未在/usr/local/lib/node_modules/@fly/fly/lib/default_context_store.js:47:30的module.exports (bundle.js:5:41)处的bundle.js:728:10 ()处定义窗口
我的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对我来说都还很新鲜,所以我甚至不确定这个错误是什么,或者它意味着什么。
有没有人能给我点启发,给我指个正确的方向?
发布于 2018-05-28 09:51:29
在你的代码中搜索“窗口”,并确保它在客户端使用!服务器或类似的时候被执行。
https://stackoverflow.com/questions/50558075
复制相似问题