gatsby: gatsby/devcert https fails: Error: "localhost" is not a valid domain name

Description

Running gatsby develop -S throws the below error. Also found that devcert might be the reason why it fails. https://github.com/davewasmer/devcert/issues/56

> xxx-abc-xyz@0.5.3 develop /home/xxxx/project 
> gatsby develop --https  

info setting up automatic SSL certificate (may require elevated permissions/sudo) 

 ERROR #11522
 
Failed to generate dev SSL certificate  

See our docs page for more info on this error: https://www.gatsbyjs.org/docs/local-https/#setup

  Error: "localhost" is not a valid domain name.  
  
  - index.js:36                
    [auth]/[devcert]/dist/index.js:36:19 
    
  - Generator.next       
  
  - tslib.js:115  
    [auth]/[tslib]/tslib.js:115:75  
    
  - new Promise 
  
  - tslib.js:111 Object.__awaiter
    [auth]/[tslib]/tslib.js:111:16

  - index.js:34 certificateFor
    [auth]/[devcert]/dist/index.js:34:20

  - get-ssl-cert.js:80 module.exports
    [auth]/[gatsby]/dist/utils/get-ssl-cert.js:80:15

  - develop.js:157 module.exports
    [auth]/[gatsby]/dist/commands/develop.js:157:49

  - next_tick.js:81 processTicksAndRejections
    internal/process/next_tick.js:81:5

  - next_tick.js:51 process.runNextTicks [as _tickCallback]
    internal/process/next_tick.js:51:3

Steps to reproduce

Any version of gatsby >= 2.19.0 fails when the cmd gatsby develop --https is run.

Expected result

Run gatsby develop --https without any error and the https endpoint should be accessible.

Actual result

Fails with the above error.

Environment

  System:
    OS: Linux 5.3 Ubuntu 18.04.4 LTS (Bionic Beaver)
    CPU: (8) x64 Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz
    Shell: 4.4.20 - /bin/bash
  Binaries:
    Node: 11.11.0 - ~/.nvm/versions/node/v11.11.0/bin/node
    Yarn: 1.22.4 - /usr/bin/yarn
    npm: 6.7.0 - ~/.nvm/versions/node/v11.11.0/bin/npm
  Languages:
    Python: 2.7.17 - /usr/bin/python
  Browsers:
    Chrome: 83.0.4103.97
    Firefox: 77.0.1
  npmPackages:
    gatsby: ^2.22.19 => 2.23.3
    gatsby-plugin-react-helmet: ^3.1.16 => 3.1.22
    gatsby-source-filesystem: ^2.1.40 => 2.1.48
  npmGlobalPackages:
    gatsby-cli: 2.12.45

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 18 (11 by maintainers)

Most upvoted comments

Hey.

As @Js-Brecht said, the error was re-introduced on version 1.21.

I was able to fix this issue by pinning devcert to 1.2.0. You can add these lines before the closing tag on your package.json.

  "overrides": {
    "gatsby": {
      "devcert": "1.2.0"
    }
  }
 

For anybody that wants to use their own self-signed certificate to workaround this issue, there’s been several methods described in #14490. For example, see my comment here. Shouldn’t need the NODE_EXTRA_CA_CERTS environment variable anymore, though. That’s been fixed.

Another way was using mkcert, in the comment above mine.

An easier workaround is to add a resolution in your package.json for ”devcert”: “1.1.0”.

{
  "resolutions": {
    "devcert": "1.1.0"
  }
}

Only works with Yarn. For PNPM, you’d need to use hooks.readPackage. There’s not really an easy way with npm to add a resolution like that

I am still running into this problem with Gatsby 2.32 and devcert 1.1.3 running ubuntu-latest. Did anyone confirm it’s working?