babel / minify

:scissors: An ES6+ aware minifier based on the Babel toolchain (beta)
https://babeljs.io/repl
MIT License
4.4k stars 225 forks source link

Cannot read property 'contexts' of null (Workaround here) #933

Open seanmorris opened 5 years ago

seanmorris commented 5 years ago

Using Babel 0.5.0 (with brunch) with the following config:

exports.plugins = {
  babel: {
    'presets': ['es2015'],
    'env': {
      'production': {
        'presets': [['minify', {

        }]]
      }
    }
  },
};

Will produce errors like the following:

17:25:50 - error: Compiling of app/article/component/HeadingMenu.js failed. TypeError: app/article/component/HeadingMenu.js: Cannot read property 'contexts' of null
    at NodePath._getQueueContexts (/home/sean/bluetheme/node_modules/babel-traverse/lib/path/context.js:278:21)
    at NodePath._containerInsert (/home/sean/bluetheme/node_modules/babel-traverse/lib/path/modification.js:94:23)
    at NodePath._containerInsertBefore (/home/sean/bluetheme/node_modules/babel-traverse/lib/path/modification.js:137:15)
    at NodePath.insertBefore (/home/sean/bluetheme/node_modules/babel-traverse/lib/path/modification.js:56:19)
    at NodePath.unshiftContainer (/home/sean/bluetheme/node_modules/babel-traverse/lib/path/modification.js:239:15)
    at BuiltInReplacer.replace (/home/sean/bluetheme/node_modules/babel-plugin-minify-builtins/lib/index.js:164:22)
    at PluginPass.exit (/home/sean/bluetheme/node_modules/babel-plugin-minify-builtins/lib/index.js:205:27)
    at newFn (/home/sean/bluetheme/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/home/sean/bluetheme/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/home/sean/bluetheme/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/home/sean/bluetheme/node_modules/babel-traverse/lib/path/context.js:117:8)
    at TraversalContext.visitQueue (/home/sean/bluetheme/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/home/sean/bluetheme/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/home/sean/bluetheme/node_modules/babel-traverse/lib/context.js:192:19)
    at Function.traverse.node (/home/sean/bluetheme/node_modules/babel-traverse/lib/index.js:114:17)
    at traverse (/home/sean/bluetheme/node_modules/babel-traverse/lib/index.js:79:12)
    at File.transform (/home/sean/bluetheme/node_modules/babel-core/lib/transformation/file/index.js:516:35)
    at /home/sean/bluetheme/node_modules/babel-core/lib/transformation/pipeline.js:50:19
    at File.wrap (/home/sean/bluetheme/node_modules/babel-core/lib/transformation/file/index.js:532:16)
    at Pipeline.transform (/home/sean/bluetheme/node_modules/babel-core/lib/transformation/pipeline.js:47:17)
    at Promise (/home/sean/bluetheme/node_modules/babel-brunch/index.js:81:26)
    at new Promise (<anonymous>:null:null)
    at BabelCompiler.compile (/home/sean/bluetheme/node_modules/babel-brunch/index.js:77:12)

Disabling "builtIns" stops this error:

exports.plugins = {
  babel: {
    'presets': ['es2015'],
    'env': {
      'production': {
        'presets': [['minify', {
          'builtIns': false
        }]]
      }
    }
  },
};
avisecag commented 5 years ago

I am experiencing the exact same problem, and the suggested workaround works great, but is there any way I can do that from the cli?