minify icon indicating copy to clipboard operation
minify copied to clipboard

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

Open bosens-China opened this issue 5 years ago • 4 comments

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

bosens-China avatar Feb 27 '19 01:02 bosens-China

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

budarin avatar Jun 23 '19 00:06 budarin

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

shrey150 avatar Jul 02 '19 02:07 shrey150

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

weyert avatar Dec 30 '19 00:12 weyert

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
         },

crra avatar Jan 14 '20 21:01 crra