javascript - 使用 'const' 关键字会在 babel 中触发错误
问题描述
我将 babel / browserify 与 gulp 和 composer 一起使用。
当我使用 const 时,它会在 gulp 中触发以下错误
(node:15308) UnhandledPromiseRejectionWarning: TypeError: C:\xampp\htdocs\plugin\wp-content\plugins\nsp-adhesion\src\js\form.js: Cannot read property 'bindings' of null while parsing file: C:\xampp\htdocs\plugin\wp-content\plugins\nsp-adhesion\src\js\form.js
at Scope.moveBindingTo (C:\xampp\htdocs\plugin\wp-content\plugins\nsp-adhesion\node_modules\@babel\traverse\lib\scope\index.js:926:13)
at convertBlockScopedToVar (C:\xampp\htdocs\plugin\wp-content\plugins\nsp-adhesion\node_modules\babel-plugin-transform-es2015-block-scoping\lib\index.js:139:13)
at PluginPass.VariableDeclaration (C:\xampp\htdocs\plugin\wp-content\plugins\nsp-adhesion\node_modules\babel-plugin-transform-es2015-block-scoping\lib\index.js:26:9)
at newFn (C:\xampp\htdocs\plugin\wp-content\plugins\nsp-adhesion\node_modules\@babel\traverse\lib\visitors.js:179:21)
at NodePath._call (C:\xampp\htdocs\plugin\wp-content\plugins\nsp-adhesion\node_modules\@babel\traverse\lib\path\context.js:55:20)
at NodePath.call (C:\xampp\htdocs\plugin\wp-content\plugins\nsp-adhesion\node_modules\@babel\traverse\lib\path\context.js:42:17)
at NodePath.visit (C:\xampp\htdocs\plugin\wp-content\plugins\nsp-adhesion\node_modules\@babel\traverse\lib\path\context.js:90:31)
at TraversalContext.visitQueue (C:\xampp\htdocs\plugin\wp-content\plugins\nsp-adhesion\node_modules\@babel\traverse\lib\context.js:112:16)
at TraversalContext.visitMultiple (C:\xampp\htdocs\plugin\wp-content\plugins\nsp-adhesion\node_modules\@babel\traverse\lib\context.js:79:17)
at TraversalContext.visit (C:\xampp\htdocs\plugin\wp-content\plugins\nsp-adhesion\node_modules\@babel\traverse\lib\context.js:138:19)
(node:15308) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15308) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
仅当它被包裹时才有效
document.addEventListener('DOMContentLoaded', function(e) {
// global variables
const test = "test";
});
这是正常行为吗?
解决方案
推荐阅读
- java - Jsoup web scrape 给了我 java.lang.NoClassDefFoundError 指向我声明文档的行,我不知道为什么?
- html - CSS不会链接到HTML,尝试了一切
- windows - 如何在 x86_64 程序集中 printf 和 scanf?
- c++ - 订购独立的可变参数模板参数
- java - 如何点击 Selenium Webdriver 和 Java
- python - 关于此代码结尾的初学者编码问题
- java - Java - 无法使用 SmbFile 连接到共享网络服务器
- acumatica - 在 2020R2 中创建销售订单付款
- assembly - 如何在 8086 汇编中将两个 16 位 dW 合并到一个 DD 数中
- javascript - 从 mysql 检索后在 html 中显示 javascript 数据