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

async+destructuring: Cannot read property '0' of null #4759

Closed
hlandau opened this issue Oct 21, 2016 · 9 comments
Closed

async+destructuring: Cannot read property '0' of null #4759

hlandau opened this issue Oct 21, 2016 · 9 comments
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@hlandau
Copy link

hlandau commented Oct 21, 2016

$ babel --version
6.16.0 (babel-core 6.17.0)
$ node --version
v6.8.1
$ cat .babelrc
{
  "presets": ["node6"],
  "plugins": ["syntax-async-functions","transform-regenerator"]
}
$ cat x.js
async function g() {
  var {x,y} = f();
}
$ babel x.js
TypeError: x.js: Cannot read property '0' of null
    at isHelper (/usr/lib/node_modules/babel-cli/node_modules/babel-generator/lib/node/whitespace.js:48:48)
    at VariableDeclaration (/usr/lib/node_modules/babel-cli/node_modules/babel-generator/lib/node/whitespace.js:103:21)
    at find (/usr/lib/node_modules/babel-cli/node_modules/babel-generator/lib/node/index.js:93:15)
    at needsWhitespace (/usr/lib/node_modules/babel-cli/node_modules/babel-generator/lib/node/index.js:115:19)
    at needsWhitespaceBefore (/usr/lib/node_modules/babel-cli/node_modules/babel-generator/lib/node/index.js:131:10)
    at Generator._printNewline (/usr/lib/node_modules/babel-cli/node_modules/babel-generator/lib/printer.js:469:11)
    at Generator.printJoin (/usr/lib/node_modules/babel-cli/node_modules/babel-generator/lib/printer.js:366:32)
    at Generator.printSequence (/usr/lib/node_modules/babel-cli/node_modules/babel-generator/lib/printer.js:422:17)
    at Generator.BlockStatement (/usr/lib/node_modules/babel-cli/node_modules/babel-generator/lib/generators/base.js:40:10)
    at /usr/lib/node_modules/babel-cli/node_modules/babel-generator/lib/printer.js:298:23

Removing async keyword: compiles.
Removing destructuring assignment: compiles.

@hzoo
Copy link
Member

hzoo commented Oct 21, 2016

might be your combination of plugins/presets - it works in the repl

@hlandau
Copy link
Author

hlandau commented Oct 21, 2016

It appears to be an issue with transform-regenerator:

$ babel --no-babelrc --plugins transform-regenerator x.js
TypeError: x.js: Cannot read property '0' of null
...

@hzoo
Copy link
Member

hzoo commented Oct 21, 2016

Ah you're right. Definitely a bug but the workaround your particular case is that you can use the https://babeljs.io/docs/plugins/transform-async-to-generator/ transform since the env is node 6

@hlandau
Copy link
Author

hlandau commented Oct 21, 2016

Yep, that works.

@EnoahNetzach
Copy link

A variant of this bug is

const dispatch = async id => ({ id })

export const getId = async () => {
  const { id } = await dispatch(42)

  return id
}

which throws the error Expected type "Expression" with option {}.

In this particular case the problem seems to be that it tries to treat an ObjectPattern as an Expression (@see) on the lhs of line 4.

@edmorley
Copy link
Contributor

Is this a bug with babel/babel-plugin-transform-regenerator's use of regenerator-transform, or solely with the latter? Just wondering if this needs to be re-filed over at:
https://github.com/facebook/regenerator/issues

Also, is there an issue filed already for improving the error messages in cases like these? The current Cannot read property '0' of null doesn't provide a line number or many other clues, so this took me a while to track down :-)

@dorianrod
Copy link

dorianrod commented Apr 27, 2018

Hi, I encountered this bug as well. I need to transform generator as my code is going to go on front end clients.
Is there a workaround ?

@OmgImAlexis
Copy link

Are there any updates to this? I believe I'm running into a similar issue.

> Error! TypeError: Cannot read property '0' of null
    at shortFromAlias (/Users/xo/code/unraid/api/node_modules/pkg/lib-es5/walker.js:68:49)
    at Walker._callee5$ (/Users/xo/code/unraid/api/node_modules/pkg/lib-es5/walker.js:891:25)
    at tryCatch (/Users/xo/code/unraid/api/node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/Users/xo/code/unraid/api/node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:296:22)
    at Generator.prototype.(anonymous function) [as next] (/Users/xo/code/unraid/api/node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:114:21)
    at step (/Users/xo/code/unraid/api/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /Users/xo/code/unraid/api/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 14, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 14, 2019
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

No branches or pull requests

7 participants