未捕获的TypeError:__ webpack_require __。i(...)不是函数

时间:2016-11-02 10:38:38

标签: javascript reactjs webpack redux

我正在

script.js:11 Uncaught TypeError: __webpack_require__.i(...) is not a function
    at Object.<anonymous> (http://localhost:8000/js/main.723b6bbbc5e319d89909.js:13057:107)
    at __webpack_require__ (http://localhost:8000/js/main.723b6bbbc5e319d89909.js:20:30)
    at Object.<anonymous> (http://localhost:8000/js/main.723b6bbbc5e319d89909.js:31776:18)
    at __webpack_require__ (http://localhost:8000/js/main.723b6bbbc5e319d89909.js:20:30)
    at http://localhost:8000/js/main.723b6bbbc5e319d89909.js:64:18
    at http://localhost:8000/js/main.723b6bbbc5e319d89909.js:67:10

第13057行是:

var browserHistory = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_6_react_router__["useRouterHistory"])(__WEBPACK_IMPORTED_MODULE_8_history_createBrowserHistory___default.a)({
  basename: ''
});

来自

的源映射
import {createStore, combineReducers} from 'redux';
import {syncHistoryWithStore, routerReducer} from 'react-router-redux';
import {useRouterHistory} from 'react-router';
import createBrowserHistory from 'history/createBrowserHistory';

const browserHistory = useRouterHistory(createBrowserHistory)({
  basename: ``
});

const store = createStore(
  combineReducers({
    chat, routing: routerReducer
  })
);

const history = syncHistoryWithStore(browserHistory, store);

我在&#34; useRouterHistory&#34;上有红色下划线,有什么想法?

这是我的webpack.config.js文件,我认为会干扰我写的代码

// changed some loader syntax after reading
// https://webpack.js.org/how-to/upgrade-from-webpack-1/

const path = require(`path`);

const webpack = require(`webpack`);
const {UglifyJsPlugin} = webpack.optimize;

const CopyWebpackPlugin = require(`copy-webpack-plugin`);
const ExtractTextWebpackPlugin = require(`extract-text-webpack-plugin`);
const configHtmls = require(`webpack-config-htmls`)();

const extractCSS = new ExtractTextWebpackPlugin(`css/style.css`);

// change for production build on different server path
const publicPath = `/`;

// hard copy assets folder for:
// - srcset images (not loaded through html-loader )
// - json files (through fetch)
// - fonts via WebFontLoader

const copy = new CopyWebpackPlugin([{
  from: `./src/assets`,
  to: `assets`
}], {
  ignore: [ `.DS_Store` ]
});

const config = {

  entry: [
    `./src/css/style.css`,
    `./src/js/script.js`
  ],

  resolve: {
    // import files without extension import ... from './Test'
    extensions: [`.js`, `.jsx`, `.css`]
  },

  output: {
    path: path.join(__dirname, `server`, `public`),
    filename: `js/[name].[hash].js`,
    publicPath
  },

  devtool: `sourcemap`,

  module: {

    rules: [
      {
        test: /\.css$/,
        loader: extractCSS.extract([
          {
            loader: `css`,
            options: {
              importLoaders: 1
            }
          },
          {
            loader: `postcss`
          }
        ])
      },
      {
        test: /\.html$/,
        loader: `html`,
        options: {
          attrs: [
            `audio:src`,
            `img:src`,
            `video:src`,
            `source:srcset`
          ] // read src from video, img & audio tag
        }
      },
      {
        test: /\.(jsx?)$/,
        exclude: /node_modules/,
        use: [
          {
            loader: `babel`
          },
          {
            loader: `eslint`,
            options: {
              fix: true
            }
          }
        ]
      },
      {
        test: /\.(svg|png|jpe?g|gif|webp)$/,
        loader: `url`,
        options: {
          limit: 1000, // inline if < 1 kb
          context: `./src`,
          name: `[path][name].[ext]`
        }
      },
      {
        test: /\.(mp3|mp4)$/,
        loader: `file`,
        options: {
          context: `./src`,
          name: `[path][name].[ext]`
        }
      }
    ]

  },

  plugins: [
    extractCSS,
    copy
  ]

};

if(process.env.NODE_ENV === `production`){

  //image optimizing
  config.module.rules.push({
    test: /\.(svg|png|jpe?g|gif)$/,
    loader: `image-webpack`,
    enforce: `pre`
  });

  config.plugins = [
    ...config.plugins,
    new UglifyJsPlugin({
      sourceMap: true, // false returns errors.. -p + plugin conflict
      comments: false
    })
  ];

}

config.plugins = [...config.plugins, ...configHtmls.plugins];

module.exports = config;

0 个答案:

没有答案