Webpack:未捕获的ReferenceError:vendor_bd98b4ed288c6b156cc9未定义

时间:2017-02-07 20:57:10

标签: javascript angular webpack webpack-2

我使用了描述here的yo生成器模板来生成一个以Angular2为前端的ASP.NET Core应用程序。但随机地,在更改css文件并保存它们(导致Webpack重新加载)后,我在客户端控制台中得到以下异常:

Uncaught ReferenceError: vendor_bd98b4ed288c6b156cc9 is not defined
    at Object.<anonymous> (external "vendor_bd98b4e…":1)
    at __webpack_require__ (bootstrap 4cd8e17…:659)
    at fn (bootstrap 4cd8e17…:83)
    at Object.module.exports (eventsource.js from dll-reference vendor_bd98b4e…:1)
    at __webpack_require__ (bootstrap 4cd8e17…:659)
    at fn (bootstrap 4cd8e17…:83)
    at Object.<anonymous> (main-client.js?v=4atoLMuOmZwmyVdq2ky2bYoBjkmqmVnuPNSIFOD8Qjs:2625)
    at __webpack_require__ (bootstrap 4cd8e17…:659)
    at module.exports (bootstrap 4cd8e17…:708)
    at bootstrap 4cd8e17…:708

dist/main-client.js文件中,我找到了以下行:

module.exports = vendor_bd98b4ed288c6b156cc9;

/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {

module.exports = (__webpack_require__(0))(0);

当我删除整个wwwroot/dist文件夹并重建Webpack包时,错误就消失了。然后,随机字符串改变如下:

module.exports = vendor_9dc79ae12948ed5e4b95;

似乎是某种缓存问题。是什么导致这个?

我正在使用Webpack 2.2.1版。

1 个答案:

答案 0 :(得分:0)

我正在关注教程并遇到同样的问题。教程说明你需要更新webpack.config.vendor.js并在添加任何新库后重新运行webpack

> webpack --config webpack.config.vendor.js
> webpack

为了将来帮助我,我将它放在我的package.json脚本下:

"scripts": {
  ... Other scripts ...
  "start": "webpack --config webpack.config.vendor.js && webpack && cross-env ASPNETCORE_ENVIRONMENT=Development dotnet run"
},
"devDependencies":{
   ... Other Dependencies ...
   "cross-env":"^5.0.1"
 }

以下是我关注的教程Content Scaling

希望这有帮助!