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

时间:2018-02-16 17:58:12

标签: node.js reactjs sitemap

当我试图读取包含路由器节点崩溃的反应文件时出错(我想构建站点地图但是即使我只是尝试使用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:未定义窗口

是否可以修复该错误?

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;

1 个答案:

答案 0 :(得分:1)

你使用react-router 4.x吗? 如果是这样,Github就会出现问题: https://github.com/kuflash/react-router-sitemap/issues/71