Error creating new project through CLI due to certificate verification issue

11 replies
Last updated: Jun 14, 2023
Hello,
Im creating a new project through the CLI and I'm having the following error:

Error: unable to verify the first certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1568:34)
    at TLSSocket.emit (node:events:511:28)
    at TLSSocket._finishInit (node:_tls_wrap:985:8)
    at ssl.onhandshakedone (node:_tls_wrap:771:12)
This is the commands and configurations used:

❯ npm -y create sanity@latest
You're setting up a new project!
We'll make sure you have an account with <http://Sanity.io|Sanity.io>. Then we'll
install an open-source JS content editor that connects to
the real-time hosted API on <http://Sanity.io|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://www.sanity.io/templates>

Looks like you already have a Sanity-account. Sweet!

βœ” Fetching existing projects
? Select project to use Create new project
? Your project name: ######
? Select organization to attach project to Mezcal Trascendente [######]
Your content will be stored in a dataset that can be public or private, depending on
whether you want to query your content with or without authentication.
The default dataset configuration has a public dataset named "production".
? Use the default dataset configuration? Yes
βœ” Creating dataset
? Project output path: /######
? Select project template Clean project with no predefined schemas
? Do you want to use TypeScript? Yes
βœ” Bootstrapping files from template
β ‹ Resolving latest module versions
AI Update

This is a common Node.js/npm TLS certificate error that typically occurs when your Node environment can't verify SSL certificates. It's not specific to Sanity, but happens during the CLI installation when npm tries to fetch packages securely. Here are the most common solutions:

Quick fixes to try:

  1. Check your Node.js version - Make sure you're using a current version of Node.js (20+ is required for Sanity Studio v4). Older versions may have outdated certificate chains:

    node --version
  2. Disable strict SSL temporarily (not recommended for production, but useful for troubleshooting):

    npm config set strict-ssl false
    npm -y create sanity@latest
    # Then re-enable it after:
    npm config set strict-ssl true
  3. Update your npm CA certificates:

    npm config set cafile ""
    npm cache clean --force
  4. Check if you're behind a corporate proxy/firewall - If you're on a corporate network, you may need to configure npm to use your company's proxy or certificate:

    npm config set proxy http://your-proxy:port
    npm config set https-proxy http://your-proxy:port
  5. Try using a different registry temporarily:

    npm config set registry https://registry.npmjs.org/

Most likely causes:

  • Corporate firewall/proxy intercepting SSL connections
  • Antivirus software interfering with SSL
  • Outdated Node.js installation with old root certificates
  • VPN or network security software

Since the error happens during "Resolving latest module versions," it's occurring when npm tries to fetch Sanity packages from the registry. Try the strict-ssl workaround first to confirm it's a certificate issue, then work on the proper solution based on your network environment.

If you're on a corporate network, you'll likely need to get the proper CA certificate from your IT team and configure npm to use it.

πŸ‘‹ Does this error happen during the
Resolving latest module versions
step?
yes
What version of Node and NPM are you running? What OS are you using?
❯ npm --v
8.5.0
❯ node --version
v16.14.2
OS: macOS 13.4
You may want to upgrade npm to the latest stable version.
upgraded my system to:
❯ node --version
v20.3.0
❯ npm --v
9.6.7
Will try again
❯ sanity init
╔═══════════════════════════════════════════════════════════════════════════════════════╗
β•‘ ⚠  Welcome to Sanity! Looks like you're following instructions for Sanity Studio v2,  β•‘
β•‘    but the version you have installed is the latest, Sanity Studio v3.                β•‘
β•‘    In Sanity Studio v3, new projects are created with [npm create sanity@latest].     β•‘
β•‘                                                                                       β•‘
β•‘    Learn more about Sanity Studio v3: <https://www.sanity.io/help/studio-v2-vs-v3>      β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

? Continue creating a Sanity Studio v3 project? (Y/n) Γ§Γ§Γ§Γ§
❯
❯
❯ npm create sanity@latest
Need to install the following packages:
  create-sanity@3.12.0
the last line is very weird
returned to
sanity init
and it worked. The other command is asking me to install the other dependency that I'd never used
Ah, that’s required as part of the process to create a V3 studio.
should I installed it globally?

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?