Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleBuildError: Module build failed: TypeError: Cannot read property 'scope' of undefined #105

Closed
irvinebroque opened this issue Aug 26, 2016 · 7 comments
Labels
bug Confirmed bug

Comments

@irvinebroque
Copy link

👋 - getting this setup with a reasonably sized production React app using Flow. All our babel versions are up-to-date.

Ran into this error, which traces back to:

https://github.com/babel/babili/blob/master/packages/babel-plugin-minify-dead-code-elimination/src/index.js#L212

Error is thrown from the entry point of the app:

/* @flow */
import React, { Component } from 'react'
import { Provider } from 'react-redux'
import { IntlProvider } from 'react-intl'
import routes from './routes'
import store from './store'

export default class App extends Component {

  static displayName = 'App';

  render() {
    return (
      <IntlProvider locale="en">
        <Provider store={store}>
          {routes}
        </Provider>
      </IntlProvider>
    )
  }
}

Stacktrace:

ModuleBuildError: Module build failed: TypeError: /Users/brendan/src/app/src/app.js: Cannot read property 'scope' of undefined
    at ReferencedIdentifier (/Users/brendan/src/app/node_modules/babel-plugin-minify-dead-code-elimination/lib/index.js:341:37)
    at newFn (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/visitors.js:318:17)
    at NodePath._call (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:192:19)
    at Function.traverse.node (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:161:17)
    at traverse (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:83:12)
    at NodePath.traverse (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/index.js:144:25)
    at /Users/brendan/src/app/node_modules/babel-plugin-minify-dead-code-elimination/lib/index.js:331:35
    at _loop3 (/Users/brendan/src/app/node_modules/babel-plugin-minify-dead-code-elimination/lib/index.js:396:16)
    at Object.enter (/Users/brendan/src/app/node_modules/babel-plugin-minify-dead-code-elimination/lib/index.js:404:23)
    at Object.newFn (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/visitors.js:318:17)
    at NodePath._call (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:192:19)
    at Function.traverse.node (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:161:17)
    at NodePath.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:115:19)
    at TraversalContext.visitQueue (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:190:19)
    at Function.traverse.node (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:161:17)
    at traverse (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:83:12)
    at NodePath.traverse (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/index.js:144:25)
    at PluginPass.Program (/Users/brendan/src/app/node_modules/babel-plugin-minify-dead-code-elimination/lib/index.js:769:14)
    at /Users/brendan/src/app/node_modules/webpack/lib/NormalModule.js:138:20
    at /Users/brendan/src/app/node_modules/loader-runner/lib/LoaderRunner.js:328:11
    at /Users/brendan/src/app/node_modules/loader-runner/lib/LoaderRunner.js:201:18
    at runSyncOrAsync (/Users/brendan/src/app/node_modules/loader-runner/lib/LoaderRunner.js:114:3)
    at iterateNormalLoaders (/Users/brendan/src/app/node_modules/loader-runner/lib/LoaderRunner.js:200:2)
    at /Users/brendan/src/app/node_modules/loader-runner/lib/LoaderRunner.js:173:4
    at Storage.finished (/Users/brendan/src/app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:39:16)
    at /Users/brendan/src/app/node_modules/graceful-fs/graceful-fs.js:78:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3)

.babelrc:

{
  "presets": ["es2015", "react"],
  "plugins": [
    "array-includes",
    "syntax-class-properties",
    "transform-class-properties",
    "transform-flow-strip-types",
    "transform-object-rest-spread",
    "transform-react-inline-elements",
    "transform-react-pure-class-to-function",
    "transform-react-remove-prop-types"
  ],
  "env": {
    "production": {
      "presets": ["babili"],
      "plugins": [
        "transform-runtime"
      ]
    },
    "development": {
      "plugins": [
        "transform-runtime",
        ["react-transform", {
          "transforms": [{
            "transform": "react-transform-hmr",
            "imports": ["react"],
            "locals": ["module"]
          }, {
            "transform": "react-transform-catch-errors",
            "imports": ["react", "redbox-react"]
          }]
        }]
      ]
    },
    "test": {
      "plugins": [
        ["transform-runtime", { "polyfill": false }]
      ]
    }
  }
}

Possibly related to these warnings, which only appear with babili turned on:

You or one of the Babel plugins you are using are using Flow declarations as bindings.
        Support for this will be removed in version 6.8. To find out the caller, grep for this
        message and change it to a `console.trace()`.

Ran with console.trace():

ModuleBuildError: Module build failed: TypeError: /Users/brendan/src/app/src/app.js: Cannot read property 'scope' of undefined
    at ReferencedIdentifier (/Users/brendan/src/app/node_modules/babel-plugin-minify-dead-code-elimination/lib/index.js:341:37)
    at newFn (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/visitors.js:318:17)
    at NodePath._call (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:192:19)
    at Function.traverse.node (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:161:17)
    at traverse (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:83:12)
    at NodePath.traverse (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/index.js:144:25)
    at /Users/brendan/src/app/node_modules/babel-plugin-minify-dead-code-elimination/lib/index.js:331:35
    at _loop3 (/Users/brendan/src/app/node_modules/babel-plugin-minify-dead-code-elimination/lib/index.js:396:16)
    at Object.enter (/Users/brendan/src/app/node_modules/babel-plugin-minify-dead-code-elimination/lib/index.js:404:23)
    at Object.newFn (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/visitors.js:318:17)
    at NodePath._call (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:192:19)
    at Function.traverse.node (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:161:17)
    at NodePath.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:115:19)
    at TraversalContext.visitQueue (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:190:19)
    at Function.traverse.node (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:161:17)
    at traverse (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:83:12)
    at NodePath.traverse (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/index.js:144:25)
    at PluginPass.Program (/Users/brendan/src/app/node_modules/babel-plugin-minify-dead-code-elimination/lib/index.js:769:14)

I tried implementing each plugin one-by-one, I get a similar error for babel-plugin-minify-constant-folding:

ModuleBuildError: Module build failed: TypeError: /Users/brendan/src/app/src/app.js: Cannot read property 'node' of undefined
    at Mangler.renameNew (/Users/brendan/src/app/node_modules/babel-plugin-minify-mangle-names/lib/index.js:188:26)
    at /Users/brendan/src/app/node_modules/babel-plugin-minify-mangle-names/lib/index.js:143:23
    at Array.map (native)
    at Scopable (/Users/brendan/src/app/node_modules/babel-plugin-minify-mangle-names/lib/index.js:135:16)
    at NodePath._call (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:192:19)
    at Function.traverse.node (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:161:17)
    at NodePath.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:115:19)
    at TraversalContext.visitQueue (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:190:19)
    at Function.traverse.node (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:161:17)
    at traverse (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:83:12)
    at NodePath.traverse (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/index.js:144:25)
    at Mangler.mangle (/Users/brendan/src/app/node_modules/babel-plugin-minify-mangle-names/lib/index.js:100:22)
    at Mangler.run (/Users/brendan/src/app/node_modules/babel-plugin-minify-mangle-names/lib/index.js:45:14)
    at PluginPass.Program (/Users/brendan/src/app/node_modules/babel-plugin-minify-mangle-names/lib/index.js:263:17)
    at newFn (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:192:19)
    at Function.traverse.node (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:161:17)
    at traverse (/Users/brendan/src/app/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:83:12)
    at /Users/brendan/src/app/node_modules/webpack/lib/NormalModule.js:138:20
    at /Users/brendan/src/app/node_modules/loader-runner/lib/LoaderRunner.js:328:11
    at /Users/brendan/src/app/node_modules/loader-runner/lib/LoaderRunner.js:201:18
    at runSyncOrAsync (/Users/brendan/src/app/node_modules/loader-runner/lib/LoaderRunner.js:114:3)
    at iterateNormalLoaders (/Users/brendan/src/app/node_modules/loader-runner/lib/LoaderRunner.js:200:2)
    at /Users/brendan/src/app/node_modules/loader-runner/lib/LoaderRunner.js:173:4
    at Storage.finished (/Users/brendan/src/app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:39:16)
    at /Users/brendan/src/app/node_modules/graceful-fs/graceful-fs.js:78:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3)

But with the following config (the preset minus the two plugins that cause issues), everything works well:

      "plugins": [
        "transform-runtime",
        "babel-plugin-transform-undefined-to-void",
        "babel-plugin-transform-simplify-comparison-operators",
        "babel-plugin-transform-property-literals",
        "babel-plugin-transform-minify-booleans",
        "babel-plugin-transform-merge-sibling-variables",
        "babel-plugin-transform-member-expression-literals",
        "babel-plugin-minify-type-constructors",
        "babel-plugin-minify-simplify",
        "babel-plugin-minify-replace",
        "babel-plugin-minify-infinity",
        "babel-plugin-minify-guarded-expressions",
        "babel-plugin-minify-flip-comparisons",
        "babel-plugin-minify-constant-folding"
      ]
@hzoo hzoo added the bug Confirmed bug label Aug 26, 2016
@hzoo
Copy link
Member

hzoo commented Aug 26, 2016

👋 Thanks for the detailed report!

@kangax
Copy link
Member

kangax commented Aug 26, 2016

I wonder why refPath is undefined here...

@boopathi
Copy link
Member

boopathi commented Aug 27, 2016

The refPath is undefined for export declaration. It is a bug in babel. babel/babel#3629

@alexeyraspopov
Copy link

Just ran into the same problem :(

@irvinebroque, do you have any workaround?

@irvinebroque
Copy link
Author

@alexeyraspopov - looks like @boopathi is working on a fix for an upcoming babel release: babel/babel#3629

kangax pushed a commit that referenced this issue Aug 29, 2016
* Add fix for other types of nodes in referencePaths

+ (Close #122)
+ (Close #105)

* return after renaming

* It's not a return

* Add tests for export statements

* Add tests for #122
@boopathi
Copy link
Member

Reopening this issue as only some related items are fixed.

This needs to be fixed from babel's side and require upgradation of babel. Don't know if there is a quick workaround for this.

@boopathi boopathi reopened this Aug 29, 2016
@boopathi
Copy link
Member

boopathi commented Jan 19, 2017

This is fixed in babel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

5 participants