Error with "async function*" when following Sanity CLI instructions

3 replies
Last updated: Apr 7, 2021
Hi there,I was trying to follow the instructions at:

https://www.sanity.io/docs/getting-started-with-sanity-cli I get an error to do with "async function*". Is there some tool I need to upgrade to a later version? See log below.
Kind regards
User

npm install -g @sanity/cli
/usr/local/bin/sanity -> /usr/local/lib/node_modules/@sanity/cli/bin/sanity
+ @sanity/cli@2.7.4
updated 1 package in 1.39s
bigmac:sanity chrisbulcock$ sanity init
You're setting up a new project!
We'll make sure you have an account with
Sanity.io . Then we'llinstall an open-source JS content editor that connects to
the real-time hosted API on
Sanity.io . Hang on.
Press ctrl + C at any time to quit.

Prefer web interfaces to terminals?
You can also set up best practice Sanity projects with
your favorite frontends on
https://sanity.io/create
Looks like you already have a Sanity-account. Sweet!

? Select project to use kayaking [5cf43c4z]
? Select dataset to use Create new dataset
? Dataset name: ds
? Choose dataset visibility – this can be changed later Public (world readable)

✔️ Creating dataset? Project output path: /Users/chrisbulcock/Projects/sanity/y
? Select project template E-commerce (schema + sample data)
? Upload a sampling of products to go with your e-commerce schema? Yes

✔️ Bootstrapping files from template
✔️ Resolving latest module versions
✔️ Creating default project files

✔️ Saved lockfile
/Users/chrisbulcock/Projects/sanity/y/node_modules/readdir-glob/index.js:62
async function* exploreWalkAsync(dir, path, followSyslinks, useStat, shouldSkip, strict) {
^
SyntaxError: Unexpected token *
at Object.<anonymous> (~/Projects/sanity/y/node_modules/archiver/lib/core.js
:9:12)
AI Update

The error you're encountering is a Node.js version compatibility issue. The async function* syntax (async generators) requires a more recent version of Node.js than what you currently have installed.

Looking at your error log, you're using @sanity/cli@2.7.4 (Sanity Studio v2), and the syntax error in readdir-glob indicates you're running an older version of Node.js that doesn't support async generators. Async generators were introduced in Node.js 10, so you're likely running Node.js 8 or earlier.

Here's how to fix this:

  1. Check your current Node.js version:

    node -v
  2. Upgrade to a supported Node.js version:

    • For the @sanity/cli@2.7.4 you installed, you should upgrade to at least Node.js 10 or higher
    • However, I'd recommend jumping to a more recent LTS version since Node.js 10 is long past end-of-life
    • If you plan to eventually upgrade to the latest Sanity Studio (v4), you'll need Node.js 20 or higher as mentioned in the Sanity documentation
  3. Install Node.js:

    • Download from nodejs.org (choose the LTS version)
    • Or use a version manager like nvm (recommended) which lets you easily switch between Node versions:
      nvm install --lts
      nvm use --lts
  4. After upgrading, try again:

    node -v  # Verify you're on a newer version
    sanity init

Note: Since you're starting fresh with the Sanity CLI getting started guide, consider that Sanity Studio v2 (which you're using) is now legacy. The current version is Sanity Studio v4, which requires Node.js 20+ and offers significant improvements. You might want to follow the latest getting started guides instead to avoid working with deprecated tooling from the start.

What is your current NodeJS version? open terminal and type
node -v
If you have a old version upgrade to the latest “stable” version. Also, try removing the
node_modules
from the root project folder like so
rm -fr node_modules
. install all the packages once again with
yarn install
and try to run
sanity start
I upgraded to Node 14.16.1 everything works now. Thanks User.
Welcome!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?