windows 当 Node.js 尝试从反应文件中读取导出默认变量时未定义(node.js 读取反应文件)

windows not defined when Node.js trying to read export default variable from react file (node.js reads react file)

当我尝试读取包含路由器节点崩溃的反应文件时出现错误(我想构建站点地图,但即使我只是尝试 console.log 导出默认变量,我也可能收到此错误babel 配置错误?):

redux\store.js:80 var store = (0, _redux.createStore)(_index2.default, defaultState, (0, _redux.compose)((0, _redux.applyMiddleware)(_reduxThunk2.default), window.devToolsExtension ? window.devToolsExtension() : function (f) { ^

ReferenceError: window is not defined

是否可以修复该错误?

react file test.js

require('es6-promise').polyfill();

import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import store, { history } from './redux/store';
import { Router, Route, IndexRoute } from 'react-router';
import App from './app';
....

const renderRouter = (<Provider store={store}>
      <Router history={history} >
        <Route path="/" component={App}>
.....
</Router>
</Prodiver
)

export default renderRouter;

站点地图文件

require('babel-register');

const renderRouter = require('./test').default;
console.log(renderRouter);

/*
const Sitemap = require('react-router-sitemap').default;

(
    new Sitemap(router)
        .build('https://www.omgomg.com')
        .save('./sitemap.xml')
);*/

编辑: 如果我删除了导入存储和历史记录,并且我从应用程序组件中收到@import 错误(它有 scss 文件,所以我相信 babel 没有配置为读取 scss?)

react file test.js

require('es6-promise').polyfill();

import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
/*import store, { history } from './redux/store';*/
import { Router, Route, IndexRoute } from 'react-router';
const App = 0;
....

const renderRouter = (<Provider >
      <Router >
        <Route path="/" component={App}>
.....
</Router>
</Prodiver
)

export default renderRouter;

你用react-router4.x吗? 如果是,则 Github 中存在问题: https://github.com/kuflash/react-router-sitemap/issues/71