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

Build Failure when babel-traverse@6.21.0 #5012

Closed
yosuke-furukawa opened this issue Dec 17, 2016 · 16 comments · Fixed by #5019
Closed

Build Failure when babel-traverse@6.21.0 #5012

yosuke-furukawa opened this issue Dec 17, 2016 · 16 comments · Fixed by #5019
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@yosuke-furukawa
Copy link

yosuke-furukawa commented Dec 17, 2016

We have got a following babel-traverse exception.

ERROR in ./src/shared/common/components/organisms/TaskModal/TaskModal.js
Module build failed: TypeError: /root/cocoroba-front/frontend/src/shared/common/components/organisms/TaskModal/TaskModal.js: Cannot read property 'declarations' of null
    at PathHoister.getAttachmentParentForPath (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/lib/hoister.js:143:137)
    at PathHoister.getAttachmentPath (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/lib/hoister.js:110:18)
    at PathHoister.run (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/lib/hoister.js:166:25)
    at NodePath.hoist (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/modification.js:263:18)
    at PluginPass.JSXElement (/root/cocoroba-front/frontend/node_modules/babel-plugin-transform-react-constant-elements/lib/index.js:39:16)
    at newFn (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:190:19)
    at Function.traverse.node (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/index.js:114:17)
    at NodePath.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/context.js:115:19)
    at TraversalContext.visitQueue (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitQueue (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:156:21)
    at TraversalContext.visitMultiple (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:190:19)
    at Function.traverse.node (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/index.js:114:17)
    at NodePath.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/context.js:115:19)
    at TraversalContext.visitQueue (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitQueue (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:156:21)
    at TraversalContext.visitMultiple (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:190:19)
    at Function.traverse.node (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/index.js:114:17)
    at NodePath.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/context.js:115:19)
    at TraversalContext.visitQueue (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitQueue (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:156:21)
    at TraversalContext.visitMultiple (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:190:19)
    at Function.traverse.node (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/index.js:114:17)
 @ ./src/shared/common/components/organisms/TaskModal/index.js 21:17-39
ERROR in ./src/shared/customer/components/atoms/AnchorLink/index.js
Module build failed: TypeError: /root/cocoroba-front/frontend/src/shared/customer/components/atoms/AnchorLink/index.js: Cannot read property 'declarations' of null
    at PathHoister.getAttachmentParentForPath (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/lib/hoister.js:143:137)
    at PathHoister.getAttachmentPath (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/lib/hoister.js:110:18)
    at PathHoister.run (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/lib/hoister.js:166:25)
    at NodePath.hoist (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/modification.js:263:18)
    at PluginPass.JSXElement (/root/cocoroba-front/frontend/node_modules/babel-plugin-transform-react-constant-elements/lib/index.js:39:16)
    at newFn (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:192:19)
    at Function.traverse.node (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/index.js:114:17)
    at NodePath.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/context.js:115:19)
    at TraversalContext.visitQueue (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:190:19)
    at Function.traverse.node (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/index.js:114:17)
    at NodePath.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/context.js:115:19)
    at TraversalContext.visitQueue (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:192:19)
    at Function.traverse.node (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/index.js:114:17)
    at NodePath.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/context.js:115:19)
    at TraversalContext.visitQueue (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:190:19)
    at Function.traverse.node (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/index.js:114:17)
    at NodePath.visit (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/path/context.js:115:19)
    at TraversalContext.visitQueue (/root/cocoroba-front/frontend/node_modules/babel-traverse/lib/context.js:150:16)
 @ ./src/shared/customer/components/atoms/Home/ActiveCategory/index.js 35:18-54

We don't know the workaround and the solution of this problem.

Input Code

import React, { Component, PropTypes } from 'react';
import { compose, setPropTypes } from 'recompose';
import { Link } from 'react-router';

export default compose(
  setPropTypes({
    isExternal: PropTypes.bool.isRequired,
    link: PropTypes.string.isRequired,
    children: PropTypes.node.isRequired,
  }),
)(class AnchorLink extends Component {
  render() {
    const { isExternal, link, children, isClosed } =  this.props;
    if (isExternal) {
      if (isClosed) {
        return (<p>{children}</p>);
      }

      return (<a href={link} target="_blank">{children}</a>);
    }

    return (<Link to={link}>{children}</Link>);
  }
});

Babel Configuration (.babelrc, package.json, cli command)

        query: {
          presets: [
            'react',
            'es2015-node4',
          ],
          plugins: [
            'syntax-trailing-function-commas',
            'transform-object-rest-spread',
            'transform-react-constant-elements',
            'transform-react-inline-elements',
          ],
        },

Expected Behavior

build success.

Current Behavior

build failure

Possible Solution

N/A

Context

Your Environment

software version
Babel v6.21
node v6.9.1
npm v3.10.1
Operating System Ubuntu
@hzoo
Copy link
Member

hzoo commented Dec 17, 2016

Do you have a minimal code snippet for this? The input code section is blank.

Looks like it's from #4940 though @appden

if (!path.parentPath ||
            (Array.isArray(path.container) && path.isStatement()) ||
            (path.isVariableDeclarator() && path.parentPath.node.declarations.length > 1))

for some reason path.parentPath.node is null

@yosuke-furukawa
Copy link
Author

yosuke-furukawa commented Dec 17, 2016

@hzoo I added example code.

@hzoo
Copy link
Member

hzoo commented Dec 17, 2016

Awesome. you should also have babel-plugin-transform-react-constant-elements running somewhere but it's not the babelrc?

@yosuke-furukawa
Copy link
Author

@hzoo ooops, my mistake. I updated the babelrc section.

@hzoo
Copy link
Member

hzoo commented Dec 17, 2016

I gotta go to sleep 😴, maybe you can pin to previous babel-traverse.

Actual workaround is to add a path.parentPath.node && check since the error is Cannot read property 'declarations' of null but probably not the fix we want

minimal code snippet so far is:

class AnchorLink extends Component {
  render() {
    const { isExternal, children, isClosed } = this.props;
    if (isExternal) {
      if (isClosed) {
        return (<p>{children}</p>);
      }

      return (<a>{children}</a>);
    }

    return (<Link>{children}</Link>);
  }
}

config has to use es2015-node4 (works with es2015)

{
    "presets": [
      "react",
      "es2015-node4"
    ],
    "plugins": [
      "transform-react-constant-elements",
      "transform-react-inline-elements"
    ]
  },

@hzoo
Copy link
Member

hzoo commented Dec 17, 2016

Haven't looked at es2015-node4 (never heard of it). Not necessarily related but I would recommend using https://github.com/babel/babel-preset-env. Not sure why you need es2015-node4 if its react + a client side app

{
  "presets": [
    ["env", {
      "targets": {
        "node": "4"
      }
    }]
  ]
}

seems to work

@hzoo hzoo added the i: bug label Dec 17, 2016
@yosuke-furukawa
Copy link
Author

Thank you. I will try.
My application is universal web apps. so we have this server side transpiler settings.

@existentialism
Copy link
Member

Even more minimal repro:

class AnchorLink extends Component {
  render() {
    const { isExternal, children } = this.props;
    if (isExternal) {
      return (<a>{children}</a>);
    }

    return (<Link>{children}</Link>);
  }
}
{
  "plugins": [
    "syntax-jsx",
    "transform-es2015-destructuring",
    "transform-react-constant-elements"
  ]
}

Will try to dig a bit more later today.

@wmertens
Copy link

wmertens commented Jan 3, 2017

I have a similar error but in a different place:

[0] Module build failed: TypeError: /myproj/some.jsx: Cannot read property 'declarations' of null
[0]     at Scope.push (/myproj/node_modules/babel-traverse/lib/scope/index.js:937:20)
[0]     at File.addTemplateObject (/myproj/node_modules/babel-core/lib/transformation/file/index.js:419:16)
[0]     at PluginPass.TaggedTemplateExpression (/myproj/node_modules/babel-plugin-transform-es2015-template-literals/lib/index.js:56:41)
[0]     at newFn (/myproj/node_modules/babel-traverse/lib/visitors.js:276:21)
[0]     at NodePath._call (/myproj/node_modules/babel-traverse/lib/path/context.js:76:18)
[0]     at NodePath.call (/myproj/node_modules/babel-traverse/lib/path/context.js:48:17)
[0]     at NodePath.visit (/myproj/node_modules/babel-traverse/lib/path/context.js:105:12)
[0]     at TraversalContext.visitQueue (/myproj/node_modules/babel-traverse/lib/context.js:150:16)
[0]     at TraversalContext.visitSingle (/myproj/node_modules/babel-traverse/lib/context.js:108:19)
[0]     at TraversalContext.visit (/myproj/node_modules/babel-traverse/lib/context.js:192:19)
[0]     at Function.traverse.node (/myproj/node_modules/babel-traverse/lib/index.js:114:17)
[0]     at NodePath.visit (/myproj/node_modules/babel-traverse/lib/path/context.js:115:19)
[0]     at TraversalContext.visitQueue (/myproj/node_modules/babel-traverse/lib/context.js:150:16)
[0]     at TraversalContext.visitMultiple (/myproj/node_modules/babel-traverse/lib/context.js:103:17)
[0]     at TraversalContext.visit (/myproj/node_modules/babel-traverse/lib/context.js:190:19)
[0]     at Function.traverse.node (/myproj/node_modules/babel-traverse/lib/index.js:114:17)
[0]     at NodePath.visit (/myproj/node_modules/babel-traverse/lib/path/context.js:115:19)
[0]     at TraversalContext.visitQueue (/myproj/node_modules/babel-traverse/lib/context.js:150:16)
[0]     at TraversalContext.visitMultiple (/myproj/node_modules/babel-traverse/lib/context.js:103:17)
[0]     at TraversalContext.visit (/myproj/node_modules/babel-traverse/lib/context.js:190:19)
[0]     at Function.traverse.node (/myproj/node_modules/babel-traverse/lib/index.js:114:17)
[0]     at NodePath.visit (/myproj/node_modules/babel-traverse/lib/path/context.js:115:19)
[0]     at TraversalContext.visitQueue (/myproj/node_modules/babel-traverse/lib/context.js:150:16)
[0]     at TraversalContext.visitSingle (/myproj/node_modules/babel-traverse/lib/context.js:108:19)
[0]     at TraversalContext.visit (/myproj/node_modules/babel-traverse/lib/context.js:192:19)
[0]     at Function.traverse.node (/myproj/node_modules/babel-traverse/lib/index.js:114:17)
[0]     at traverse (/myproj/node_modules/babel-traverse/lib/index.js:79:12)
[0]     at File.transform (/myproj/node_modules/babel-core/lib/transformation/file/index.js:558:35)
[0]     at /myproj/node_modules/babel-core/lib/transformation/pipeline.js:50:19
[0]     at File.wrap (/myproj/node_modules/babel-core/lib/transformation/file/index.js:574:16)

So the problem is at https://github.com/babel/babel/blob/master/packages/babel-traverse/src/scope/index.js#L783

I added a console log at that location, and it is related to tagged template literals; the value of declarPath is too large to list, and the declarator is

{ type: 'VariableDeclarator',
  id: { type: 'Identifier', name: '_templateObject4' },
  init: 
   { type: 'CallExpression',
     callee: { type: 'Identifier', name: '_taggedTemplateLiteral' },
     arguments: [ [Object], [Object] ],
     _compact: true } }

@wmertens
Copy link

wmertens commented Jan 3, 2017

Ah, when I disable babel-preset-babili, it doesn't crash…

@ilionic
Copy link

ilionic commented Jan 20, 2017

Any updates on this one? First was getting it and had to downgrade to 6.20.0 Now getting it again:

Error TypeError: /app/Page.react.js: Cannot read property 'declarations' of null
at PathHoister.getAttachmentParentForPath (/app/node_modules/babel-register/node_modules/babel-traverse/lib/path/lib/hoister.js:143:137)
at PathHoister.getAttachmentPath (/app/node_modules/babel-register/node_modules/babel-traverse/lib/path/lib/hoister.js:110:18)
at PathHoister.run (/app/node_modules/babel-register/node_modules/babel-traverse/lib/path/lib/hoister.js:166:25)
at NodePath.hoist (/app/node_modules/babel-register/node_modules/babel-traverse/lib/path/modification.js:263:18)
at PluginPass.JSXElement (/app/node_modules/babel-plugin-transform-react-constant-elements/lib/index.js:39:16)
at newFn (/app/node_modules/babel-register/node_modules/babel-traverse/lib/visitors.js:276:21)
at NodePath._call (/app/node_modules/babel-register/node_modules/babel-traverse/lib/path/context.js:76:18)
at NodePath.call (/app/node_modules/babel-register/node_modules/babel-traverse/lib/path/context.js:48:17)
at NodePath.visit (/app/node_modules/babel-register/node_modules/babel-traverse/lib/path/context.js:105:12)
at TraversalContext.visitQueue (/app/node_modules/babel-register/node_modules/babel-traverse/lib/context.js:150:16)
at TraversalContext.visitSingle (/app/node_modules/babel-register/node_modules/babel-traverse/lib/context.js:108:19)
at TraversalContext.visit (/app/node_modules/babel-register/node_modules/babel-traverse/lib/context.js:192:19)
at Function.traverse.node (/app/node_modules/babel-register/node_modules/babel-traverse/lib/index.js:114:17)
at NodePath.visit (/app/node_modules/babel-register/node_modules/babel-traverse/lib/path/context.js:115:19)
at TraversalContext.visitQueue (/app/node_modules/babel-register/node_modules/babel-traverse/lib/context.js:150:16)
at TraversalContext.visitSingle (/app/node_modules/babel-register/node_modules/babel-traverse/lib/context.js:108:19)
at TraversalContext.visit (/app/node_modules/babel-register/node_modules/babel-traverse/lib/context.js:192:19)

(not using babili)

@aoc
Copy link

aoc commented Jan 20, 2017

@ilionic if you rollback a direct dependency it doesn't mean it will rollback its dependencies. For example, If you take a look at babel-core's package.json you'll see it looks for the latest babel-traverse 6.x.x version. So even if you go back to babel-core@6.20.0, it will get babel-traverse@6.22.0.

You can easily check the babel-traverse version you're using by looking at /app/node_modules/babel-register/node_modules/babel-traverse/package.json

I'm using yarn, so I manually edited yarn.lock file and set babel-traverse@6.20.0 (exact version) in babel-core@6.20.0. This solution is far from ideal, but works. (And I have to reapply it when a change another dependency :( )

@hzoo
Copy link
Member

hzoo commented Jan 20, 2017

Sorry forgot about this one in the last release all, will do a patch.

Can temp remove the constant-elements plugin as a workaround (there are some other existing bugs we need to solve still)

hzoo pushed a commit that referenced this issue Jan 20, 2017
@hzoo
Copy link
Member

hzoo commented Jan 20, 2017

Ok released babel-traverse@6.22.1, babel-core@6.22.1, babel-cli@6.22.1 for folks using npm 2.

@ilionic
Copy link

ilionic commented Jan 20, 2017

@aoc Yes I am aware of that, took quite a bit of time to investigate. I had to explicitly add and set "babel-traverse": "6.20.0" which fixed the issue for some time.
@hzoo many thanks!

@aoc
Copy link

aoc commented Jan 20, 2017

thanks @hzoo babel-traverse@6.22.1 fixed it for me (yarn v0.19.1)

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 5, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants