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

Optional Chaining Not Working in gatsby-node.js #23802

Closed
graysonhicks opened this issue May 5, 2020 · 3 comments
Closed

Optional Chaining Not Working in gatsby-node.js #23802

graysonhicks opened this issue May 5, 2020 · 3 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@graysonhicks
Copy link
Contributor

Description

I noticed optional chaining was added out of the box, which is great. However, I noticed that optional chaining works in source files, but not in the root level gatsby-node.js file.

Steps to reproduce

Go to this sandbox and look at the terminal and the gatsby-node.js file: https://codesandbox.io/s/fervent-lehmann-3hvlb?file=/gatsby-node.js

Expected result

Should be able to use optional chaining throughout the project including plugins, not just inside components, pages and templates. Should not need a library like dlv just for these files, the babel preset should cover the entire project.

Actual result

See this error:

Error: /sandbox/gatsby-node.js:10
    const useChain = actions?.optionalChaining
                             ^
  SyntaxError: Unexpected token .

Environment

Note: this is info from the CodeSandbox terminal:

    OS: Linux 4.19 Debian GNU/Linux 10 (buster) 10 (buster)
    CPU: (12) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
    Shell: 5.0.3 - /bin/bash
  Binaries:
    Node: 10.20.1 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    gatsby: ^2.21.0 => 2.21.0
    gatsby-image: ^2.4.0 => 2.4.0
    gatsby-plugin-manifest: ^2.4.0 => 2.4.0
    gatsby-plugin-offline: ^3.2.0 => 3.2.0
    gatsby-plugin-react-helmet: ^3.3.0 => 3.3.0
    gatsby-plugin-sharp: ^2.6.0 => 2.6.0
    gatsby-source-filesystem: ^2.3.0 => 2.3.0
    gatsby-transformer-sharp: ^2.5.0 => 2.5.0```
@graysonhicks graysonhicks added the type: bug An issue or pull request relating to a bug in Gatsby label May 5, 2020
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label May 5, 2020
@danabrit danabrit added status: needs dx review type: question or discussion Issue discussing or asking a question about Gatsby and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby labels May 5, 2020
@pieh
Copy link
Contributor

pieh commented May 6, 2020

@graysonhicks Optional chaining works in files that in some way are handled by webpack - that includes all source files as well as gatsby-browser and gatsby-ssr. It doesn't actually work in gatsby-node (or gatsby-config), because those files are read as-is and only features that are supported by you current Node.js version will work. Optional chaining didn't land yet in Node so unfortunately you can't use it there yet (even after updating to latest Node version) ... unless you would have build/transpile step for your gatsby-node.

We will be adding some kind of support for running babel on those automatically (as part of efforts to completely support typescript out of the box), so this would solve both problem you described as well as add typescript support, but it's not yet implemented.

@graysonhicks
Copy link
Contributor Author

@pieh Yea that's what I was thinking. Will be nice to see this added. Thanks.

@LekoArts
Copy link
Contributor

Thank you for opening this!

Since the original issue was answered I'll close this one. You can follow #18983 to see how our TS progress goes. Implicitly out of this you'll then also be able to use it - for now that's not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

4 participants