未捕获的TypeError:无法读取未定义的属性“webpackHotUpdate”

问题描述 投票:2回答:1

当浏览器点击“webpackified”app.js文件中的以下行时,我收到此错误:

/******/ (function(modules) { // webpackBootstrap
/******/    function hotDisposeChunk(chunkId) {
/******/        delete installedChunks[chunkId];
/******/    }
/******/    var parentHotUpdateCallback = this["webpackHotUpdate"];

在这个片段的最后一行,this未定义。

尽管有这个错误,该应用似乎运行得很好。

我不确定我的webpack.config.js文件的哪些部分最相关,但这里有一些可能相关的片段:

webpack.config.js

const HotModuleReplcement = new webpack.HotModuleReplacementPlugin();

...

module.exports = {

  ...

  devServer: {
    historyApiFallback: true,
    hot: true,
    inline: true,
    port: 8000,
    open: true,
    proxy: [{
      context: ['/assets', '/api'],
      target: 'http://localhost:4000',
      secure: false
    }]
  },
  plugins: [HotModuleReplcement, HtmlWebpack]
};

知道这里发生了什么吗?

javascript webpack webpack-dev-server
1个回答
0
投票

核心问题是"this"应该是网页的"self"(而不是节点)。

webpack.config.js不应该是:

output: {
    path: 'dist',
      filename: '[name].js',
      publicPath: '/',
      globalObject: 'this'
  },

但应该更像这样:

output: {
    path: 'dist',
      filename: '[name].js',
      publicPath: '/',
      globalObject: 'self'
  },

More from webpack.js.org

© www.soinside.com 2019 - 2024. All rights reserved.