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

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

Closed
ngmgit opened this issue Jun 17, 2020 · 18 comments
Closed

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

ngmgit opened this issue Jun 17, 2020 · 18 comments
Labels
type: upstream Issues outside of Gatsby's control, caused by dependencies

Comments

@ngmgit
Copy link

ngmgit commented Jun 17, 2020

Description

Running gatsby develop -S throws the below error.
Also found that devcert might be the reason why it fails. davewasmer/devcert#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
@ngmgit ngmgit added the type: bug An issue or pull request relating to a bug in Gatsby label Jun 17, 2020
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jun 17, 2020
@ngmgit
Copy link
Author

ngmgit commented Jun 17, 2020

Also for now the solution to use latest gatsby and avoid the issue is to provide the cert and key files using flags this skips devcert. Atleast for me it works and doesn't halt my work.

@Js-Brecht
Copy link
Contributor

Js-Brecht commented Jun 17, 2020

See davewasmer/devcert#57

@ascorbic ascorbic added type: upstream Issues outside of Gatsby's control, caused by dependencies 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 Jun 18, 2020
@ascorbic
Copy link
Contributor

Closing as this seems to be a devcert issue that should hopefuly be fixed soon

@Js-Brecht
Copy link
Contributor

For anyone coming to this later, you can also pin devcert to v1.1.0. The issue was introduced in v1.1.1

@JustFly1984
Copy link

JustFly1984 commented Jun 19, 2020

@ascorbic please reopen, @Js-Brecht pinning devcert to 1.1.0 helped to fix running gatsby develop -S locally, but in Github actions linux ubuntu 18 it still fails with error:

Screenshot 2020-06-19 16 49 57

while running clean install (with removing yarn.lock, .cache and node_modules I see warning from devcert:

warning devcert@1.1.0: secuurity vulnerability fixed in v1.1.1

rverting gatsby back to 2.23.2 does not help too.

@ascorbic
Copy link
Contributor

That still sounds like a devcert error, rather than a problem with Gatsby

@Js-Brecht
Copy link
Contributor

Js-Brecht commented Jun 19, 2020

@JustFly1984 that is a devcert issue, but one unrelated to this one. If libnss is not installed, then it will attempt to install it for you. It is either trying to install the wrong library for Ubuntu 18, or the CI doesn’t have the correct apt sources.

devcert doesn’t really support CI/CD... it’s going to require too much intervention. I guess one way would be to disable the automatic setup of libnss... it’s only going to be needed for browsers anyway, and you probably won’t be running a browser in CI. That should be done from Gatsby; it could use either a new CLI parameter, or watch for process.env.CI to change that configuration parameter when calling devcert. That particular parameter is here:

skipCertutilInstall: false,

However, all that aside, I still don’t think I’d recommend running devcert in CI/CD. I’m not even sure why you’d run gatsby develop at all in CI/CD.


You will see the warning about the security vulnerability; no way around that. It’s a feature of the package manager. Version 1.1.1 fixed a potential remote execution exploit, so a warning was placed on 1.1.0... but that’s not really something you would need to worry about when running gatsby develop. It’s something you’d need to worry about if you’re running devcert in production.

@JustFly1984
Copy link

@Js-Brecht we are running gatsby develop -S, cos it is faster than running gatsby build and run webserver to run it with cypress. Currently cypress silently running with dev server with gatsby@2.23.4. devcert rolled back to 1.1.0, and we are installing libnss into github actions ubuntu docker

@lalasmuathasim
Copy link

lalasmuathasim commented Jun 29, 2020

I also faced the same issue the steps I did to rectify this are

1 - Created a certificate and key using OpenSSL (For windows machine - https://helpcenter.gsx.com/hc/en-us/articles/115015960428-How-to-Generate-a-Self-Signed-Certificate-and-Private-Key-using-OpenSSL) - The steps will be different for Mac and Linux but the Idea might be same

2 - Copy the Certificate and Key file to the project folder

3 - Then run the command yarn dev -S --key-file ./privateKey.key --cert-file ./certificate.crt

@outaTiME
Copy link
Contributor

outaTiME commented Jul 4, 2020

Same here on mac 😢 workaround ?

@lalasmuathasim
Copy link

Same here on mac 😢 workaround ?

Have you tried creating pivatekey and certificate then running yarn dev -S --key-file ./privateKey.key --cert-file ./certificate.crt

@Js-Brecht
Copy link
Contributor

Js-Brecht commented Jul 5, 2020

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

@outaTiME
Copy link
Contributor

outaTiME commented Jul 5, 2020

awesome @Js-Brecht the resolutions works as expected with yarn 👍

@Js-Brecht
Copy link
Contributor

devcert version 1.1.2 is published. It should fix this issue.

@marcustisater
Copy link
Contributor

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?

@NoahDavidATL
Copy link

Getting this issue with Gatsby 4.13.1

@Js-Brecht
Copy link
Contributor

@NoahDavidATL a new version of devcert was released a couple of days ago, which introduced this issue. You may want to open a new ticket. This could be fixed by pinning the devcert version to 1.2.0

davewasmer/devcert#79
davewasmer/devcert#83

@martinszajt
Copy link

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"
    }
  }
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: upstream Issues outside of Gatsby's control, caused by dependencies
Projects
None yet
Development

No branches or pull requests

9 participants