babel / babel/minify

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

Open
#946 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
4.4k
Forks
217
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**

**To Reproduce**

Minimal code to reproduce the bug

```js
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,

```js
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! configure@1.0.0 build: `cross-env NODE_ENV=production webpack --config build/webpack.prod.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the configure@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
```

**Expected Output**

```js
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:

```json5
{
removeConsole: true,
keepFnNames: true
}
```

babelrc:

```json5
{
plugins: [],
presets: []
}
```

**Possible solution**

**Additional context**

Contributor guide

Open the contributing guide

Research direction

Reproduce the webpack4 build with babel-minify 0.4.3 and Babel 7.0.0-beta.49, then inspect babel-plugin-minify-simplify/lib/index.js around PluginPass.Program and the NodePath.getSource stack frame in @babel/traverse/lib/path/introspection.js. Done means the build no longer throws the getCode error and produces successful output.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.