首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ReferenceError:窗口未使用ReactJS定义

ReferenceError:窗口未使用ReactJS定义
EN

Stack Overflow用户
提问于 2018-05-28 09:32:12
回答 1查看 3.3K关注 0票数 0

晚上好,我正在Ubuntu上使用react 16.3.2,我想将我的新react应用程序与this software集成。

我的webpack.fly.config.js文件:

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
import React from 'react';
import ReactDOM from 'react-dom';

ReactDOM.render(
  <h1>Hello, world!</h1>,
  document.getElementById('root')
);

和我的index.html:

代码语言:javascript
复制
<!-- 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对我来说都还很新鲜,所以我甚至不确定这个错误是什么,或者它意味着什么。

有没有人能给我点启发,给我指个正确的方向?

EN

回答 1

Stack Overflow用户

发布于 2018-05-28 09:51:29

在你的代码中搜索“窗口”,并确保它在客户端使用!服务器或类似的时候被执行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50558075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档