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

Unexpected token '?' after upgrading from 0.0.5 -> 0.1.0 #7

Closed
nbaosullivan opened this issue Mar 16, 2021 · 4 comments
Closed

Unexpected token '?' after upgrading from 0.0.5 -> 0.1.0 #7

nbaosullivan opened this issue Mar 16, 2021 · 4 comments

Comments

@nbaosullivan
Copy link

nbaosullivan commented Mar 16, 2021

I receive this error when upgrading. Is it worth just replacing the usages of ?? with || (if falsey check is applicable) to avoid any compiler issues?

  Error:[..]node_modules/gatsby-plugin-extract-schema/gatsby-node.js:13
      const location = options.dest ?? defaultLocation;
                                     ^
  SyntaxError: Unexpected token '?'

Edit: forgot to mention I tried the suggested addition of babel-preset-gatsby in babel config, but that did not help.

@NickyMeuleman
Copy link
Owner

Hey!
Is this on a node version that's older than 14?
It's the nullish coalescing operator that was added in v14.
Later in the code, optional chaining is used too, also a v14+ feature.
https://node.green/#ES2020-features--nullish-coalescing-operator-----

@chrbala
Copy link
Contributor

chrbala commented May 6, 2021

Is there a reason why you need to publish code that uses features not supported below 14? node 12 is still in maintenance for another year.

https://nodejs.org/en/about/releases

The following does basically the same thing as the current gatsby-node.js without breaking older versions.

const write = require("write");
const path = require("path");
const { printSchema } = require("gatsby/graphql");

exports.onPostBootstrap = async ({ store }, options) => {
  try {
    const defaultLocation = path.resolve(process.cwd(), "schema.graphql");
    const defaultGetSchema = async (obj) =>
      printSchema(obj, { commentDescriptions: true });
    const defaultWriteSchema = async (location, schema) =>
      write(location, schema);

    const location = options.dest || defaultLocation;
    const { schema: internalSchemaObj } = store.getState();
    const getSchema = options.getSchema || defaultGetSchema
    let schema = (await getSchema(internalSchemaObj));
    schema = options.adjustSchema ? await options.adjustSchema(schema) : schema;

    const writeSchema = options && options.writeSchema || defaultWriteSchema;
    await writeSchema(location, schema);

    console.log("[gatsby-plugin-extract-schema] Wrote schema");
  } catch (error) {
    console.error(
      "[gatsby-plugin-extract-schema] Failed to write schema: ",
      error
    );
  }
};

@NickyMeuleman
Copy link
Owner

NickyMeuleman commented May 6, 2021

node 12 is still in maintenance for another year.

You're right :), I wanted to use those features but don't have to in this case.
The code you posted is even more readable too!
Awesome!

Do you want to create a PR with that @chrbala? Looking at it, that can be merged immediately.

@marcus13371337
Copy link

marcus13371337 commented May 6, 2021

Thanks for the great plugin!

Encountered this problem today as well. Just to emphasize backwards compatibility, this is from gatsby docs:

Gatsby takes backwards compatibility seriously and aims to support older versions of Node.js for as long as possible. We understand that juggling different software versions is not a productive way to spend your day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants