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

Can't generate certificates on fresh install #262

Closed
ethanroday opened this issue Jul 25, 2017 · 35 comments
Closed

Can't generate certificates on fresh install #262

ethanroday opened this issue Jul 25, 2017 · 35 comments
Assignees
Milestone

Comments

@ethanroday
Copy link
Contributor

Steps to reproduce:

  1. npm install -g preact-cli
  2. preact create <app> --yarn
  3. cd <app>
  4. yarn serve

Result:

Setting up SSL certificate (may require sudo)...
INFO: Could not find files for the given pattern(s).
Attempting to spawn simplehttp2server to generate cert.
Failed to generate dev SSL certificate: Error: spawn C:\<app_dir>\node_modules\simplehttp2server\vendor\simplehttp2server_windows_amd64.exe ENOENT
Falling back to shared directory + simplehttp2server.
(dir: C:\Users\<username>\AppData\Roaming\preact-cli)

  server error> Error: spawn C:\<app_dir>\node_modules\simplehttp2server\vendor\simplehttp2server_windows_amd64.exe ENOENT
Error: spawn C:\<app_dir>\node_modules\simplehttp2server\vendor\simplehttp2server_windows_amd64.exe ENOENT

Environment:

OS: Windows 10 x64
Terminal: Powershell (Administrator mode) (PSVersion: 5.1.14393.1480)

@thangngoc89
Copy link
Collaborator

Hi. ENOENT means there is no such file. Could you run yarn install inside your project folder again to make sure everything get installed?

@ethanroday
Copy link
Contributor Author

ethanroday commented Jul 25, 2017

I'm fairly certain the file exists...I can navigate to it in a terminal (and an Explorer window). Did a yarn install just to be sure.
Also, I think the simplehttp2server is not the only issue here. The devcert library is also failing to generate the SSL certificates.

@zweehn
Copy link

zweehn commented Jul 27, 2017

I have the same problem and copy pasting the ENOENT file in powershell and executing it works

PS F:\sources\Node\my-preact> npm run serve

 my-preact@1.0.0 serve F:\sources\Node\my-preact
 preact build && preact serve

Build [==================  ] 91% (1.1s) additional asset processing
  Total precache size is about 144 kB for 14 resources.
Setting up SSL certificate (may require sudo)...
INFORMATION: Es konnten keine Dateien mit dem angegebenen
Muster gefunden werden.
Attempting to spawn simplehttp2server to generate cert.
Failed to generate dev SSL certificate: Error: spawn F:\sources\Node\my-preact\node_modules\simplehttp2server\vendor\simplehttp2server_windows_amd64.exe ENOENT
Falling back to shared directory + simplehttp2server.
(dir: C:\Users\User\AppData\Roaming\preact-cli)

  server error> Error: spawn F:\sources\Node\my-preact\node_modules\simplehttp2server\vendor\simplehttp2server_windows_amd64.exe ENOENT
Error: spawn F:\sources\Node\my-preact\node_modules\simplehttp2server\vendor\simplehttp2server_windows_amd64.exe ENOENT

PS F:\sources\Node\my-preact> F:\sources\Node\my-preact\node_modules\simplehttp2server\vendor\simplehttp2server_windows_amd64.exe
2017/07/27 18:51:18 Listening on https://localhost:5000...

I think it worked the first time i installed preact-cli
npm start (preact watch) works

@anantoghosh
Copy link
Contributor

I have also encountered this problems and looked into it:
preact serve works on bash for windows, not on powershell and cmd.

  1. devcert-san requires openssl in Path
    Since Bash for windows has openssl, everything works as expected. I get a prompt for installing the certificate, application starts serving from https://localhost:8080

  2. when generating through simplehttp2serve

let child = execFile(simplehttp2server, ['-listen', ':40210'], {
		cwd,
		encoding: 'utf8'
	},

shouldn't this be in the form cwd: cwd ?
I got cwd as C:\Users\usename\AppData\Roaming\preact-cli
There was no folder preact-cli inside Roaming

Creating the folder solved the ENOENT problem, but simplehttp2server shows no console output

Had to pipe to get output

2017/08/11 23:11:16 Generating certificate...
2017/08/11 23:11:17 written cert.pem
2017/08/11 23:11:17 written key.pem
2017/08/11 23:11:17 Listening on https://localhost:40210...

It stays at that and the callback isn't called.
Not sure how to proceed now, any help @thangngoc89 ?

@thangngoc89
Copy link
Collaborator

thangngoc89 commented Aug 11, 2017

shouldn't this be in the form cwd: cwd ?

It's ES6 short-hand syntax, same thing.

Could you try and create the cwd folder ? I don't see any obvious bug here.

btw, Windows sucks. The cwd vs Powershell alone is a huge headache. I'm using Linux Subsystem for development and never comeback

@anantoghosh
Copy link
Contributor

@thangngoc89 I did that already. It did start simplehttp2server, but it is stuck at Listening on https://localhost:40210...

@reznord
Copy link
Member

reznord commented Aug 22, 2017

@ethanroday the issue is when you bootstrap a project using preact-cli, it doesn't run yarn build command.

Can you please run the build and try to run yarn serve?

I got bit by this a couple of times. probably I'll add the npm run -s build to the postinstall script, that should do the work.

@ethanroday
Copy link
Contributor Author

I thought yarn build ran preact build && preact serve anyway?
Regardless, I seem to have found a way around the problem. If I just do the setup in Git Bash rather than in Powershell everything works just fine.
Not sure whether you want to still consider this an issue - since this means it still doesn't work out of the box on Windows - so I will leave it open.

@kaseyhinton
Copy link

kaseyhinton commented Sep 22, 2017

Had this same problem today. I did the setup in Git Bash and it isn't working. Still haven't found a solution.

@SimplyComplexable
Copy link

Encountered this today. Only solution I could find was to use Git's bash. Bash for the win!
Disclaimer: I'm using npm, not yarn.

@redstrike
Copy link

Still encountered this issue today. Preact-CLI v2.1.0

image

Steps to produce the error:

  1. Create a new project from any template.
  2. cd new-project & yarn serve

yarn start & yarn build work normally.

It seems a problem with yarn serve only.

I wonder why my getting started UX in any dev project is always awful 😂 Anyway, I'm so glad to know that a lot of awesome works has been done since v1.1.2 😍

@developit
Copy link
Member

Does this work if you install git within WSL?

@jgierer12
Copy link
Contributor

For the record, I had a similar issue but it wouldn't even work within WSL or Git Bash.

Turned out npm install didn't run simplehttp2server's install script so the node_modules/simplehttp2server/vendor/simplehttp2server_windows_amd64.exe file really didn't exist. A simple npm install --no-save simplehttp2server fixed it for me.

@joacim88
Copy link

I got the same issue and i tried the npm install --nosave.. but it did not do the trick.

preact serve Setting up SSL certificate (may require sudo)... INFO: Could not find files for the given pattern(s). Attempting to spawn simplehttp2server to generate cert. Failed to generate dev SSL certificate: Error: spawn C:\Users\joagun\AppData\Roaming\npm\node_modules\preact-cli\node_modules\simplehttp2server\vendor\simplehttp2server_windows_amd64.exe ENOENT Falling back to shared directory + simplehttp2server.

I know this has worked before and the funny thing is that the .exe does exist.

@joacim88
Copy link

Alright, I solved it.

So I'm typing my commands in the VS Code prompt. Try changing it to cmder with admin rights. Worked for me.

@felipewer
Copy link

Hey guys, I've also stumbled upon this error on Linux (Fedora).

My error output gave me a better hint of what is happening (2nd line):

Setting up SSL certificate (may require sudo)...
cp: cannot create regular file '/usr/local/share/ca-certificates/devcert.cer': No such file or directory
Attempting to spawn simplehttp2server to generate cert.
Failed to generate dev SSL certificate: Error: spawn /home/felipewer/projects/startup_buzzer/frontend/node_modules/simplehttp2server/vendor/simplehttp2server_linux_amd64 ENOENT
Falling back to shared directory + simplehttp2server.
(dir: /home/felipewer/.preact-cli)

  server error> Error: spawn /home/felipewer/projects/startup_buzzer/frontend/node_modules/simplehttp2server/vendor/simplehttp2server_linux_amd64 ENOENT
Error: spawn /home/felipewer/projects/startup_buzzer/frontend/node_modules/simplehttp2server/vendor/simplehttp2server_linux_amd64 ENOENT

Looks like an ENOENT error happens when trying to copy the devcert.cer file to /usr/local/share/ca-certificates/. This error is probably not properly handled, so it bubbles up the stack.

Creating the /usr/local/share/ca-certificates/ folder manually solved the problem and now npm run serve works. But this is only a workaround. I'll take a look at the code next, hopefully soon!

@ghost
Copy link

ghost commented Nov 11, 2018

Same issue here :(
I cannot use preact serve.
I am running on windows 7, same errors as above, workarounds didn't work.

@skdigital
Copy link

skdigital commented Dec 9, 2018

I am running into this issue currently, nightmare, tried everything it seems with no luck.

My system:

Windows 10 64bit
NVM with Node stable and 11x (on linux subsystem)
Node 11x on Windows 10
Latest Preact CLI

I tried:

  1. Yarn add simplehttp2servers (didnt work)
  2. Tried yarn serve && NPM run serve with Windows Subsystem Linux Shell, Git Bash, Powershell, CMD, CMDr, HyperTerminal (with elevated admin and Sudo command. It fails everytime. Even after installing simplehttp2server locally and globally with both npm and yarn.

Steps to reproduce:

  1. npm install -g preact-cli
  2. preact create --yarn || standard npm
  3. cd
  4. yarn serve || npm run serve etc...

Result:
yarn run v1.12.3
$ preact build --no-service-worker --template src/template.html && preact serve
Setting up SSL certificate (may require sudo)...
Attempting to spawn simplehttp2server to generate cert.
Failed to generate dev SSL certificate: Error: spawn C:\Users\Sean Knowles\Desktop\Dev\preact\opsap-web\node_modules\simplehttp2server\vendor\simplehttp2server_windows_amd64.exe ENOENT
Falling back to shared directory + simplehttp2server.
(dir: C:\Users\Sean Knowles\AppData\Roaming\preact-cli)

server error> Error: spawn C:\Users\Sean Knowles\Desktop\Dev\preact\opsap-web\node_modules\simplehttp2server\vendor\simplehttp2server_windows_amd64.exe ENOENT
Error: spawn C:\Users\Sean Knowles\Desktop\Dev\preact\opsap-web\node_modules\simplehttp2server\vendor\simplehttp2server_windows_amd64.exe ENOENT

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

image

@skdigital
Copy link

Lol just noticed these issues have been going on for over a year, whats the problem, seems that this devCert thing is causing big issues for windows users. I dont have any of these issues with Nextjs or Reactjs, its just with Preact, I cant build and serve the production version.

@redstrike
Copy link

It has been a year since my last post 😂.
I'm not using preact-cli as my main dev tool due to this problem.
Had better improving our webpack-fu instead of relying on the cli.

@skdigital
Copy link

Yea same, was literally testing Preact CLI for an mvp then came across this issue and am moving away, it might be trivial but the issue hasn't been resolved for quite some time.

@lukeed
Copy link
Member

lukeed commented Dec 10, 2018

Not sure why I'm assigned. This wasn't a smooth process for me either. Part of the reason why I've advocated to get rid of serve entirely for next release.

This is a permissions thing, and we're totally at the mercy of what simplehttp2server is permitted to do.

My guess is that it has to do with how users' machines have installed node and npm. Specifically, if sudo is granted to the installation or not. Since 99% of the reports here are Windows, I'm betting that's the case.

@EvanDarwin
Copy link

What's wrong with just using webpack-dev-server? Then users can have hot reloading, but I'm not sure if that will conflict with the pre-rendering step.

@lukeed
Copy link
Member

lukeed commented Dec 11, 2018

The serve command was added for testing within a http2, production-like setting. WDS does not offer that feature

@skdigital
Copy link

Is there a solution, because currently windows users are having trouble/impossible to test production build locally... surely there is a better solution? Basics issues like these just turns me away from using a technology if you catch my drift. This issue has been here for over a year, and just hasn't really been addressed. Admittedly I am junior dev and have no idea how big a fix this is. Is there another way I can test the local build?

@lukeed
Copy link
Member

lukeed commented Dec 11, 2018

@skdigital Sure, understood. As mentioned it's not something we actually have control over. The best solution was to just get rid of it going forward. In the interim, you can just use any http server on the production directory. For example, I use sirv-cli for testing. There's no HTTP/2 (yet) but the important part (imo) is to just get it up & running as a sanity check.

$ npm install -g sirv-cli
$ npm run build
$ sirv build --single

@skdigital
Copy link

Cheers boss, working nice!

@skdigital
Copy link

Is there a discord or slack channel for Preact?

@lukeed
Copy link
Member

lukeed commented Dec 13, 2018

Great! Yup we're over in https://preact.slack.com

@ForsakenHarmony
Copy link
Member

Thought you might be the most appropriate person talk about this, that's why I assigned you

@robinbakker
Copy link

I had the same issues running serve. Another alternative on Windows with VS Code is to use the IIS Express extension (in VS Code).

  1. When the extension is enabled, use "IIS Express: Start Website" from the command menu (Ctrl-Shift-P)
  2. It will run and fail... But we have generated a settings file now 🙂
  3. Use the "Stop Website" command.
  4. See the .vscode dir in your project and edit the iisexpress.json file. Change the path to the build folder and set protocol to "https". Also, change the port to a value from the range 44300-44399.
  5. Now you can use "Start Website" and it runs your build folder as long as you have your VS Code window open or until you use the "Stop Website" command. So you can just do a npm run build anytime after that and refresh your browser to check the production build.

@ahmadrasyidsalim
Copy link

ahmadrasyidsalim commented Feb 26, 2019

Not sure why I'm assigned. This wasn't a smooth process for me either. Part of the reason why I've advocated to get rid of serve entirely for next release.

This is a permissions thing, and we're totally at the mercy of what simplehttp2server is permitted to do.

My guess is that it has to do with how users' machines have installed node and npm. Specifically, if sudo is granted to the installation or not. Since 99% of the reports here are Windows, I'm betting that's the case.

Install Git on your Windows, run it as administrator, create a sample preact project, then it will be no issue when you run yarn serve or npm run serve

@EvanDarwin
Copy link

EvanDarwin commented Mar 1, 2019

...or maybe we can just use a server that actually works? HTTP/2 is an unnecessary feature. If they really want it that badly, they can use their own solution.

For me right now, all the serve command does is frustrate Windows users and confuse developers trying to run their app the first time.

@rrsoftcz
Copy link

rrsoftcz commented Oct 1, 2019

Have same problem on Ubuntu 18.04.

I just a little bit looking around and I discovered that simplehttp2server folder not included vendor folder with binary file. I simply navigated into /node_modules/simplehttp2server/ and install the binnary:

$ cd /node_modules/simplehttp2server/
$ npm install
$ cd <back to project root>
$ preact serve

The vendor directory has created include missed binary file and preact serve start working.
I don't know the reason why they all needed dependencies has not successfully installed by "npm install" inside the project, but only want to help to solve this issue without waste time to find the main reason.

@developit
Copy link
Member

@rrsoftcz simplehttp2server was removed in Preact CLI version 3 (currently in preview) since the preact serve command was removed (for now).

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

No branches or pull requests