简体   繁体   中英

using 'const' keyword triggers an error in babel

I use babel / browserify with gulp and composer.

When I use const it triggers the following error in 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.

It works only if it's wrapped in

document.addEventListener('DOMContentLoaded', function(e) {
   // global variables
   const test = "test";    
});

Is it a normal behavior?

Found the answer in this post,

was a mismatch of babel dependencies between 6 & 7

JavaScript babel "TypeError: Cannot read property 'bindings' of null" when trying to transpile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM