Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable/Ignore Babel strict mode for transpiling javascript files

I am trying to transpile a set of js files.As babel by default operates in a strict mode,it outputs a syntax error whenever there is a conflict for example use of a delete keyword.The solution I am looking for is to somehow ignore this strict mode. Please note that I am doing above operation using babel cli and that there is no project set-up.

Edit: I am aware of how delete works in strict mode.The question is to use babel to operate in non-strict mode so that it won't give errors as by default it parses files as ES6 modules.

babel delete keyword conflict in strict mode

like image 447
Shashank Singh Avatar asked Mar 06 '26 02:03

Shashank Singh


1 Answers

I have figured out the solution.By default Babel parses the files as ES6 modules, which are strict by default.If we add the --source-type script in case one is using cli,then it will work.I am writing a simple command to transpile a single js file which will ignore strict mode,in case someone gets stuck on this in future.One key note is you need to upgrade to latest babel 7 to make it work.

babel test.js --presets=@babel/env --source-type script --out-file test_new.js
like image 187
Shashank Singh Avatar answered Mar 08 '26 15:03

Shashank Singh