【发布时间】:2016-09-02 22:21:49
【问题描述】:
我正在尝试重写使用 require.js 的旧应用程序以使用 es6 导入。使用的库之一是 Backbone 和 Underscore。为了创建一个大包并将 es6 预编译为 es5,我使用 Webpack 和 babel-loader。 Bundle 已创建,但是当我在浏览器中加载它时出现以下错误:
Uncaught TypeError: Cannot read property '_' of undefined
似乎下划线中的“this”在创建的 bundle.js 中未定义,所以 root._ 给了我错误。
// Baseline setup
// --------------
// Establish the root object, `window` in the browser, or `global` on the server.
var root = this;
// Save the previous value of the `_` variable.
var previousUnderscore = root._;
// Establish the object that gets returned to break out of a loop iteration.
var breaker = {}
有人遇到过同样的问题吗?
【问题讨论】:
-
你的
babel-loaderwebpack 配置是什么?您可能遗漏了exclude: /node_modules/的内容。 -
Tnx 很多!将
exclude: /node_modules/添加到babel-loaderwebpack 配置解决了问题!
标签: javascript ecmascript-6 webpack underscore.js