babel-plugin-remove-use-strict
raw JSON → 1.0.1 verified Sat Apr 25 auth: no javascript
A Babel plugin that removes all `"use strict"` directives from JavaScript code. Version 1.0.1 is the current stable release; the package has minimal updates and is essentially feature-complete. It is a niche utility for projects where strict mode is unwanted (e.g., legacy code, certain bundling scenarios). Unlike manual regex-based removal, this plugin integrates directly into the Babel pipeline and respects AST, avoiding false positives in string literals or comments.
Common errors
error Error: Could not find plugin 'babel-plugin-remove-use-strict'. Ensure it is installed. ↓
cause Missing npm install or incorrect plugin name.
fix
Run 'npm install babel-plugin-remove-use-strict' and use short name 'remove-use-strict' in config.
error SyntaxError: Unexpected token (1:1) while parsing "use strict" ↓
cause Input code is not JavaScript (e.g., JSON) or has syntax error.
fix
Ensure input is valid JavaScript; the plugin works on AST, not raw text.
error TypeError: this.Opportunities is not a function ↓
cause Babel version mismatch (e.g., using Babel 6 plugin in Babel 7).
fix
Use a Babel 7 compatible version or fork the plugin.
Warnings
gotcha String literals containing 'use strict' (e.g., in console.log) are NOT removed. ↓
fix The plugin only removes directive nodes; ensure you understand the AST distinction.
gotcha The plugin is designed for Babel 6/7; compatibility with Babel 8 is untested. ↓
fix Test with your Babel version; consider contributing if issues arise.
gotcha Removing 'use strict' may change module behavior in ES modules or Node.js; it's not polyfilled. ↓
fix Only use if you understand the implications of disabling strict mode globally.
Install
npm install babel-plugin-remove-use-strict yarn add babel-plugin-remove-use-strict pnpm add babel-plugin-remove-use-strict Imports
- default wrong
import removeUseStrict from 'babel-plugin-remove-use-strict'correctmodule.exports = { plugins: ["remove-use-strict"] } - plugin name string wrong
"babel-plugin-remove-use-strict"correct"remove-use-strict" - require("@babel/core").transform wrong
require("@babel/core").transform(code, { plugins: [require("babel-plugin-remove-use-strict")] })correctrequire("@babel/core").transform(code, { plugins: ["remove-use-strict"] })
Quickstart
// .babelrc
{
"plugins": ["remove-use-strict"]
}
// Input
"use strict";
function f() {
"use strict";
console.log("use strict");
}
// Output
function f() {
console.log("use strict");
}