Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After installing babel I get an exception of undeclared variable [duplicate]

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

like image 348
IsraGab Avatar asked Feb 02 '26 20:02

IsraGab


1 Answers

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"
  ]
like image 76
IsraGab Avatar answered Feb 05 '26 08:02

IsraGab