Minify: Using plug-ins to report errors Cannot read property 'getCode' of undefined

Created on 27 Feb 2019  路  4Comments  路  Source: babel/minify

Describe the bug

To Reproduce

Minimal code to reproduce the bug

const {
  production,
} = require('./config/index');

const date = {
  presets: [
    [
      '@babel/preset-env',
      {
        useBuiltIns: 'usage',
      },
    ],
    '@babel/preset-typescript',
  ],
  plugins: ['@babel/proposal-class-properties', '@babel/proposal-object-rest-spread'],
};
if (production) {
  date.presets.push('minify');
  date.plugins.push('transform-remove-console', 'transform-remove-debugger',
    'minify-dead-code-elimination', 'minify-guarded-expressions', 'minify-mangle-names',
    'minify-replace', 'minify-simplify', 'transform-undefined-to-void', 'minify-type-constructors',
    'transform-merge-sibling-variables', 'transform-minify-booleans');
}

module.exports = date;

Actual Output

If there is no Error thrown,

Module build failed (from ./node_modules/happypack/loader.js):
TypeError: Cannot read property 'getCode' of undefined
    at NodePath.getSource (C:\Users\Administrator\Desktop\WebPackMultiPageConfiguration\node_modules\@babel\traverse\lib\path\introspection.js:164:27)
    at PluginPass.Program (C:\Users\Administrator\Desktop\WebPackMultiPageConfiguration\node_modules\babel-plugin-minify-simplify\lib\index.js:490:41)
    at newFn (C:\Users\Administrator\Desktop\WebPackMultiPageConfiguration\node_modules\@babel\traverse\lib\visitors.js:193:21)
    at NodePath._call (C:\Users\Administrator\Desktop\WebPackMultiPageConfiguration\node_modules\@babel\traverse\lib\path\context.js:53:20)
    at NodePath.call (C:\Users\Administrator\Desktop\WebPackMultiPageConfiguration\node_modules\@babel\traverse\lib\path\context.js:40:17)
    at NodePath.visit (C:\Users\Administrator\Desktop\WebPackMultiPageConfiguration\node_modules\@babel\traverse\lib\path\context.js:88:12)
    at TraversalContext.visitQueue (C:\Users\Administrator\Desktop\WebPackMultiPageConfiguration\node_modules\@babel\traverse\lib\context.js:118:16)
    at TraversalContext.visitSingle (C:\Users\Administrator\Desktop\WebPackMultiPageConfiguration\node_modules\@babel\traverse\lib\context.js:90:19)
    at TraversalContext.visit (C:\Users\Administrator\Desktop\WebPackMultiPageConfiguration\node_modules\@babel\traverse\lib\context.js:146:19)
    at Function.traverse.node (C:\Users\Administrator\Desktop\WebPackMultiPageConfiguration\node_modules\@babel\traverse\lib\index.js:94:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `cross-env NODE_ENV=production webpack --config build/webpack.prod.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Expected Output

Successful output

Stack Trace

If applicable,


Configuration

How are you using babel-minify?

webpack4

babel-minify version: 0.4.3

babel version : 7.0.0-beta.49

babel-minify-config:

{
  removeConsole: true,
  keepFnNames: true
}

babelrc:

{
  plugins: [],
  presets: []
}

Possible solution

Additional context

Most helpful comment

Hello @shrey150,

Can confirm this error occurs when babel-plugin-minify-mangle-names is in .babelrc plugins

Do you use the preset minify by any chance? If so you need to remove the plugin from the plugin section and set the options via the preset. e.g:

"env": {
  "production": {
    "presets": [
      ["minify", {
        "mangle": {
           "topLevel": true,
           "keepFnName": false,
           "keepClassName": false
         },

All 4 comments

I also have this error if babel-plugin-closure-elimination is in plugins array

Can confirm this error occurs when babel-plugin-minify-mangle-names is in .babelrc plugins

Yes, I have this problem to with Storybook when I am using Typescript

Hello @shrey150,

Can confirm this error occurs when babel-plugin-minify-mangle-names is in .babelrc plugins

Do you use the preset minify by any chance? If so you need to remove the plugin from the plugin section and set the options via the preset. e.g:

"env": {
  "production": {
    "presets": [
      ["minify", {
        "mangle": {
           "topLevel": true,
           "keepFnName": false,
           "keepClassName": false
         },
Was this page helpful?
0 / 5 - 0 ratings