After installing babel I get an exception of undeclared variable

Viewed 523

In my current project I have a lot of global variables: (not declared with var)

HELLO = 'Hello';

I installed babel so I can use all the ES next functions, but it seems babel doesn't now how to deal with global variables

.babelrc

{
  "presets": [
    [
    "@babel/preset-env",
    {
      "modules": "commonjs"
    }
  ]
  ],
  "plugins": ["angularjs-annotate"]
}

UPDATE!!

Seems that it comes from babel transpiling. Babel added: "use strict"; . That's why my code failed

2 Answers

you can achieve global by assign var to the window like so:

window.HELLO = 'hello';

Ok. It takes me a while to figure it out.

here's the solution: Add that to the plugins in .babelrc

"plugins": [
    ["@babel/plugin-transform-modules-commonjs", {
    "strictMode": false
  }],
      "angularjs-annotate"
  ]
Related