diff --git a/packages/commonjs/README.md b/packages/commonjs/README.md index 31b1f1e6d..c52fe1be2 100644 --- a/packages/commonjs/README.md +++ b/packages/commonjs/README.md @@ -123,7 +123,7 @@ Sometimes you have to leave require statements unconverted. Pass an array contai ### `ignoreTryCatch` Type: `boolean | 'remove' | string[] | ((id: string) => boolean)`
-Default: `false` +Default: `true` In most cases, where `require` calls are inside a `try-catch` clause, they should be left unconverted as it requires an optional dependency that may or may not be installed beside the rolled up package. Due to the conversion of `require` to a static `import` - the call is hoisted to the top of the file, outside of the `try-catch` clause. diff --git a/packages/commonjs/src/index.js b/packages/commonjs/src/index.js index 09925de34..ef3976f3b 100644 --- a/packages/commonjs/src/index.js +++ b/packages/commonjs/src/index.js @@ -88,7 +88,9 @@ export default function commonjs(options = {}) { ? options.ignoreTryCatch(id) : Array.isArray(options.ignoreTryCatch) ? options.ignoreTryCatch.includes(id) - : options.ignoreTryCatch || false; + : typeof options.ignoreTryCatch !== 'undefined' + ? options.ignoreTryCatch + : true; return { canConvertRequire: mode !== 'remove' && mode !== true,