react-codemod icon indicating copy to clipboard operation
react-codemod copied to clipboard

Error when running rename-unsafe-lifecycles

Open wesleyyee opened this issue 5 years ago • 9 comments

Seeing this error when running rename-unsafe-lifecycles:

Error: did not recognize object of type "ImportExpression"
    at Object.getFieldNames (/Users/wes/.npm/_npx/76919/lib/node_modules/react-codemod/node_modules/ast-types/lib/types.js:701:19)
    at getSortedChildNodes (/Users/wes/.npm/_npx/76919/lib/node_modules/react-codemod/node_modules/recast/lib/comments.js:50:23)
    at getSortedChildNodes (/Users/wes/.npm/_npx/76919/lib/node_modules/react-codemod/node_modules/recast/lib/comments.js:63:9)
    at decorateComment (/Users/wes/.npm/_npx/76919/lib/node_modules/react-codemod/node_modules/recast/lib/comments.js:73:22)
    at decorateComment (/Users/wes/.npm/_npx/76919/lib/node_modules/react-codemod/node_modules/recast/lib/comments.js:84:13)
    at decorateComment (/Users/wes/.npm/_npx/76919/lib/node_modules/react-codemod/node_modules/recast/lib/comments.js:84:13)
    at decorateComment (/Users/wes/.npm/_npx/76919/lib/node_modules/react-codemod/node_modules/recast/lib/comments.js:84:13)
    at decorateComment (/Users/wes/.npm/_npx/76919/lib/node_modules/react-codemod/node_modules/recast/lib/comments.js:84:13)
    at /Users/wes/.npm/_npx/76919/lib/node_modules/react-codemod/node_modules/recast/lib/comments.js:129:9
    at Array.forEach (<anonymous>)```

wesleyyee avatar Feb 12 '20 21:02 wesleyyee

Could you try to isolate what file this happened on? If you could make a git repo with a reduced usecase, that would be excellent.

Just to be sure that it isn’t related to your own dependencies, would you also try running this from outside your project? ie- instead of cd my-project and npx react-codemod ..., could you run `npx react-codemod my-project‘?

threepointone avatar Feb 12 '20 21:02 threepointone

Ahh it seems to not like React.lazy

wesleyyee avatar Feb 13 '20 14:02 wesleyyee

@threepointone https://github.com/wesleyyee/codeshift-react-lazy

wesleyyee avatar Feb 14 '20 15:02 wesleyyee

Very helpful, thank you! I'll have a look this weekend.

threepointone avatar Feb 18 '20 14:02 threepointone

@threepointone Did you ever solve this? I have a similar problem in a codemod I am writing where it chokes on the dynamic import.

Not using React.lazy, but same syntax with loadable:

const Dooby = loadable(
  () => import('dooby/doo'),
  {
    fallback: <LoadingPage />
  }
);

Jayphen avatar May 15 '20 14:05 Jayphen

I'm not doing any active development on this, but I'd be happy to review and land a PR with a fix.

threepointone avatar Jul 07 '20 17:07 threepointone

Hey, not sure if related, but also getting a similar error Error: did not recognize object of type "ChainExpression" with the same stack trace when running rename-unsafe-lifecycles

sterlu avatar Aug 24 '20 12:08 sterlu

@sterlu I had the same ChainExpression error when running over our large non-TS codebase - it seems to choke on optional chaining operators ?..

By telling the codemod to treat the code as Typescript it worked though.

rbalmf avatar Oct 11 '20 14:10 rbalmf

try npx react-codemod rename-unsafe-lifecycles it'll work

parthakshay avatar Apr 14 '22 10:04 parthakshay