loganfsmyth / babel-plugin-transform-decorators-legacy

A plugin for Babel 6 that (mostly) replicates the old decorator behavior from Babel 5
MIT License
817 stars 57 forks source link

Error: We don't know what to do with this node type ..... #8

Closed miketheanimal closed 8 years ago

miketheanimal commented 8 years ago

Since this is a legacy/maintain old functionality plugin, I'm just reporting this, I realise it may not be worth fixing, the plugin is great anyway and has saved me a lot of trouble :)

The following (stripped down a bit) works:

import CSSModules from 'react-css-modules' ;
import styles from './accordion.css' ;
export function layoutAccordion (Header, Content) {
    class __Accordion extends React.Component {
        ....
        }
    return CSSModules(__Accordion, styles) ;
    }

but the decorated version doesn't:

import CSSModules from 'react-css-modules' ;
import styles from './accordion.css' ;
export function layoutAccordion (Header, Content) {
    @CSSModules(styles)
    class __Accordion extends React.Component {
        ....
        }
    return __Accordion
    }

The full error:

Error: app/layout/accordion.js: We don't know what to do with this node type. We were previously a Statement but we can't fit in here?
    at NodePath.insertBefore (/usr/lib/node_modules/babel-cli/node_modules/babel-core/node_modules/babel-traverse/lib/path/modification.js:62:13)
    at NodePath.unshiftContainer (/usr/lib/node_modules/babel-cli/node_modules/babel-core/node_modules/babel-traverse/lib/path/modification.js:254:15)
    at Scope.push (/usr/lib/node_modules/babel-cli/node_modules/babel-core/node_modules/babel-traverse/lib/scope/index.js:1031:41)
    at Scope.generateDeclaredUidIdentifier (/usr/lib/node_modules/babel-cli/node_modules/babel-core/node_modules/babel-traverse/lib/scope/index.js:308:10)
    at /home/mike/applify2/node_modules/babel-plugin-transform-decorators-legacy/lib/index.js:27:56
    at Array.map (native)
    at applyEnsureOrdering (/home/mike/applify2/node_modules/babel-plugin-transform-decorators-legacy/lib/index.js:25:53)
    at PluginPass.ClassExpression (/home/mike/applify2/node_modules/babel-plugin-transform-decorators-legacy/lib/index.js:223:38)
    at newFn (/usr/lib/node_modules/babel-cli/node_modules/babel-core/node_modules/babel-traverse/lib/visitors.js:278:19)
    at NodePath._call (/usr/lib/node_modules/babel-cli/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:76:18)
loganfsmyth commented 8 years ago

This sounds like an instance of https://phabricator.babeljs.io/T3051, if you update your version of babel-traverse you should be all set.

loganfsmyth commented 8 years ago

Closing, but feel free to let me know if that doesn't work.

silkentrance commented 8 years ago

For those who are having the same problem, you need to install babel-traverse@6.3.19 globally if you have babel / babel-cli installed globally, too. Otherwise, this will not work.

loganfsmyth commented 8 years ago

Yes, sorry should have clarified. babel-traverse is a subdependency of babel-core, so really you'll need to update your primary babel install. The easiest thing to do is probably delete and reinstall Babel.

Installing babel globally is also generally not recommended.

silkentrance commented 8 years ago

@loganfsmyth I tried, babel-core is at version 6.3.13 and so is babel-traverse when installing it via npm. The only way for me to make this work was to manually install babel-traverse@6.3.19.

loganfsmyth commented 8 years ago

@silkentrance Babel uses ranges. babel-core is at 6.3.17 but it depends on babel-traverse@^6.3.17 which means it will install >=6.3.17 < 7.0.0

silkentrance commented 8 years ago

@loganfsmyth perhaps we should tell npm@3.3.4 to behave that way :grin:, at least on my system, that is.