0

I am trying to set up Babel compiler which converts ES6 and higher Javascript syntax to ES5. However, I faced one weird problem, when it converts to ES5 adds "use strict" in the top of the line, since the whole project is not written in strict mode it causes errors. I would like to disable this functionality. I have seen a couple of solutions online but none of them worked for me. I followed these steps link but did not work.

This is how my package.json looks like:

{
  "name": "webplatform",
  "version": "1.0.0",
  "description": "Web interface Platform",
  "scripts": {
    "build": "babel htdocs/es6 -d htdocs/js"
  },
  "author": "harry",
  "license": "ISC",
  "devDependencies": {
    "@babel/cli": "^7.4.3",
    "@babel/core": "^7.4.3",
    "@babel/plugin-transform-strict-mode": "^7.2.0",
    "@babel/preset-env": "^7.4.3"
  }
}

And .babelrc is here

{
  "presets": ["@babel/preset-env"],
  "plugins": [
    ["@babel/plugin-transform-strict-mode", {
      "strict": false
    }]
  ]
}

When I run the command npm run build it converts everything fine just "use strict" is messing me up :(

n1md7
  • 2,854
  • 1
  • 12
  • 27
  • yo check all responses of this post? https://stackoverflow.com/questions/33821312/how-to-remove-global-use-strict-added-by-babel – Black Hole Apr 15 '19 at 14:30
  • @Olian04 I have seen that source but did not work for me. – n1md7 Apr 15 '19 at 14:32
  • 1
    There are tons of answers there, please try some of the more recent ones. For example: https://stackoverflow.com/a/43024673/6224823 – Olian04 Apr 15 '19 at 14:36
  • @Olian04 My project is written in PHP and there are more like node-based answers and the rest are the same steps I have used. But I will check them all again :( – n1md7 Apr 15 '19 at 14:40
  • https://stackoverflow.com/questions/6020178/can-i-disable-ecmascript-strict-mode-for-specific-functions – gilbert-v Apr 15 '19 at 14:44
  • 1
    https://stackoverflow.com/questions/52827968/babel-7-how-to-prevent-adding-of-strict-mode – Nathan Apr 15 '19 at 16:28
  • https://stackoverflow.com/questions/34973442/how-to-stop-babel-from-transpiling-this-to-undefined-and-inserting-use-str/34983495#34983495 should cover this. – loganfsmyth Apr 15 '19 at 16:56
  • @NathanWright Thanks a lot that worked for me. Adding `"sourceType": "script"` in `.babelrc` fixed my issue – n1md7 Apr 16 '19 at 07:37

0 Answers0