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

Failing under Widnows #15

Closed
AgainPsychoX opened this issue Sep 3, 2021 · 9 comments
Closed

Failing under Widnows #15

AgainPsychoX opened this issue Sep 3, 2021 · 9 comments

Comments

@AgainPsychoX
Copy link

Describe the bug

Under Windows, installing the certs fail. In order to access C:\Program Files\* admin privileges are required. On the other hand, why would it install

Reproduction

  1. Use the plugin under Windows without admin

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

  System:
    OS: Windows 10 10.0.19043
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 3.81 GB / 15.85 GB
  Binaries:
    Node: 16.3.0 - C:\Program Files\nodejs\node.EXE
    npm: 7.21.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 92.0.4515.159
    Edge: Spartan (44.19041.1023.0), Chromium (92.0.902.84)
    Internet Explorer: 11.0.19041.1

Used package manager: npm

Logs

First time error (without vite --debug flag but still)

error when starting dev server:
Created a new local CA 💥
The local CA is now installed in the system trust store! ⚡️
Note: Firefox support is not available on your platform. ℹ️
ERROR: failed to execute "keytool -importcert": exit status 1

Certificate was added to keystore
keytool error: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.8.0_211\jre\lib\security\cacerts (Odmowa dost�pu)

    at ChildProcess.exithandler (node:child_process:326:12)
    at ChildProcess.emit (node:events:394:28)
    at ChildProcess.emit (node:domain:470:12)
    at maybeClose (node:internal/child_process:1067:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)

Second try error:

  vite:config bundled config file loaded in 238ms +0ms
  vite:plugin:mkcert The hosts changed from [undefined] to [localhost,192.168.55.6,127.0.0.1], start regenerate certificate +0ms
error when starting dev server:
Error: Command failed: C:\Users\PsychoX\.vite-plugin-mkcert\mkcert.exe -install -key-file C:\Users\PsychoX\.vite-plugin-mkcert\certs\dev.key -cert-file C:\Users\PsychoX\.vite-plugin-mkcert\certs\dev.pem localhost 192.168.55.6 127.0.0.1
The local CA is already installed in the system trust store! 👍
Note: Firefox support is not available on your platform. ℹ️
ERROR: failed to execute "keytool -importcert": exit status 1

Certificate was added to keystore
keytool error: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.8.0_211\jre\lib\security\cacerts (Odmowa dost�pu)


    at ChildProcess.exithandler (node:child_process:326:12)
    at ChildProcess.emit (node:events:394:28)
    at ChildProcess.emit (node:domain:470:12)
    at maybeClose (node:internal/child_process:1067:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)

@AgainPsychoX
Copy link
Author

AgainPsychoX commented Sep 3, 2021

After a bit of investigation, I realized its mkcert the admin rights. If it's called only on (re)generating the certs - so, once or rarely - I think the plugin should just start it as elevated process.

Powershell could be used to run process elevated:

util.promisify(child_process.exec)(`Start-Process cmd -Verb RunAs -Wait -ArgumentList '/c cd ${process.cwd()} && cmd'`, {shell: 'powershell.exe'})
.then(x => console.log(x)) // supports waiting for finish too
  • If user was not elevated, the UAC dialog appears. If user agrees to elevate, the process run. On disagree, exception is fired.
  • If user was already elevated, there is no dialog, everything runs smoothly.
  • There is small issue with this solution: additional terminal window will appear for a time the elevated process is running (but it's better than not working at all).

I will try to create pull request in few hours or a day. If I haven't it means I forgot.

@AgainPsychoX
Copy link
Author

AgainPsychoX commented Sep 3, 2021

I am having issues with PNPM you are using... A lot of ERR_PNPM_FETCH_404 errors... It seems PNPM is ignoring how registry works (it try to download https://registry.npmjs.org/speedometer/download/speedometer-1.0.0.tgz when registry tells the tarball is at https://registry.npmjs.org/speedometer/-/speedometer-1.0.0.tgz). I don't think it directly your fault, but I can't really contribute.

See pnpm/pnpm#3744

@liuweiGL
Copy link
Owner

liuweiGL commented Sep 3, 2021

keytool error: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.8.0_211\jre\lib\security\cacerts (Odmowa dost�pu)

Please try again after remove jdk environment setting.

@liuweiGL
Copy link
Owner

liuweiGL commented Sep 3, 2021

I don't see any logs related to the permission problem.

@AgainPsychoX
Copy link
Author

AgainPsychoX commented Sep 3, 2021

Yeah, that works too (but it removes the variable for whole vite instead only mkcert):

cross-env JAVA_HOME= vite

Shouldn't it be added when using the binary then? Like:

const env = Object.assign({}, process.env);
env.JAVA_HOME = '';
util.promisify(child_process.exec)('cmd', {env});

It says "Access denied" ("Odmowa dostępu" in Polish) in the log

keytool error: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.8.0_211\jre\lib\security\cacerts (Odmowa dost�pu)

Sorry for closing, miss-click ;_;

@AgainPsychoX
Copy link
Author

@liuweiGL Can hiding JAVA_HOME be added if its running on Windows?
utils.ts, around like 62:

export const exec = async (cmd: string) => {
  if (process.platform === 'win32') {
    const env = Object.assign({}, process.env)
    env.JAVA_HOME = ''
    return await util.promisify(child_process.exec)(cmd, {env})
  }
  else {
    return await util.promisify(child_process.exec)(cmd)
  }
}

If you can add that it would be nice. (I can't use PNPM anyway so I can't do it myself)

@liuweiGL
Copy link
Owner

liuweiGL commented Sep 3, 2021

I am sorry, i hope the plugin sticks to its responsibilities and keeps it simple and clean.

@liuweiGL liuweiGL closed this as completed Sep 3, 2021
@AgainPsychoX
Copy link
Author

So I should unset JAVA_HOME for whole building process? It's so messy...

@liuweiGL
Copy link
Owner

You are right, we don't need support install into java cacerts file.

I will take your advice, thank you.

@liuweiGL liuweiGL reopened this Feb 24, 2022
liuweiGL added a commit that referenced this issue Feb 25, 2022
github-actions bot pushed a commit to skymoonya/rsbuild-plugin-mkcert that referenced this issue Mar 14, 2024
# 1.0.0 (2024-03-14)

### Bug Fixes

* additional path escaping issue [liuweiGL#80](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/80) ([liuweiGL#81](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/81)) ([a3bbe6c](a3bbe6c))
* fix access denied error caused by JAVA_HOME ([f4f7c18](f4f7c18)), closes [liuweiGL#15](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/15)
* fix built assets error ([12a2de4](12a2de4))
* fix import commonjs modules error ([d7bfaa0](d7bfaa0))
* fix npm package not includes built files ([da701ee](da701ee)), closes [liuweiGL#31](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/31)
* fix the error caused by the path containing spaces ([655bfa4](655bfa4)), closes [liuweiGL#17](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/17)
* fix tsc report an type error ([3695e8c](3695e8c))
* fix wrong debug log ([510d381](510d381))
* generated code include vite code ([e5adc6b](e5adc6b)), closes [liuweiGL#47](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/47)
* get warning from esbuild build ([7e4d968](7e4d968))
* Illegal operation in linux ([d299720](d299720)), closes [liuweiGL#63](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/63)
* local hosts not include ips in node18 ([b710399](b710399))
* local path warning only if path isn't found ([liuweiGL#32](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/32)) ([ac7f533](ac7f533))
* mkcert initialization error ([b8e6e96](b8e6e96)), closes [liuweiGL#62](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/62)
* not working if the mkcert in directory with special charaters ([e3a5b63](e3a5b63)), closes [liuweiGL#61](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/61)
* Plugin‘s type definition is not generic ([1d031d1](1d031d1)), closes [liuweiGL#44](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/44)
* **plugin:** fix linux system permission denied ([bc9c93e](bc9c93e)), closes [liuweiGL#7](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/7)
* **plugin:** mkcert binary lost ([liuweiGL#13](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/13)) ([d4a881b](d4a881b))
* preview mode can use https ([liuweiGL#28](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/28)) ([048a8d1](048a8d1))
* rollback required node version ([782ab10](782ab10))
* **script:** fix read config.json error ([bb227c7](bb227c7))
* **script:** fix release workflow wrong ([d0cf9a3](d0cf9a3))
* **script:** 修复发包之前没有构建资源 ([dbd4b76](dbd4b76))
* **script:** 修复获取最新版本号错误 ([d4ce4c7](d4ce4c7))
* the plugin reports mkcert not recognized as an internal or external command when  parentheses in the folder name ([02278c8](02278c8)), closes [liuweiGL#83](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/83)
* typescript 5.0.2 can not resolve typings ([d070319](d070319)), closes [liuweiGL#65](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/65)
* typescript can't correct resolve .d.ts file ([363d66a](363d66a))
* upgrade dependencies, fix vulnerability ([8c2c0b1](8c2c0b1)), closes [liuweiGL#76](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/76)
* vite version range incorrect ([1486c44](1486c44))
* 修复node14不支持replaceAll导致报错的问题 ([liuweiGL#66](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/66)) ([6936de3](6936de3))

### Features

*  allow force to generate certificate ([ce4c4e0](ce4c4e0))
* add `savePath` `keyFileName`  `certFileName` parameters ([b12de07](b12de07)), closes [liuweiGL#56](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/56)
* add log informations ([1f9c356](1f9c356))
* add logger prefix ([bee34ee](bee34ee))
* always include local hosts ([6bab2ec](6bab2ec))
* complete 1.0 version ([b3773a0](b3773a0))
* complete coding.net mirror setting ([f663270](f663270))
* complete the initial version ([6316831](6316831))
* dev downloader ([9c084e2](9c084e2))
* dev mkcert downloader ([ff9b411](ff9b411))
* export BasetSource-class ([liuweiGL#37](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/37)) ([3f25861](3f25861))
* https is enabled by default ([d1b8197](d1b8197))
* **plugin:** add certificate cache ([e07be64](e07be64))
* **plugin:** plugin only works in serve mode ([d471652](d471652))
* **plugin:** 支持自定义域名 ([liuweiGL#11](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/11)) ([fd6f58e](fd6f58e))
* pretty write config.json file ([0a556ab](0a556ab))
* retain the existing ca ([ee85a33](ee85a33)), closes [liuweiGL#59](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/59)
* rsbuild-plugin-mkcert ([6299325](6299325))
* save CA file to savePath ([6b29fe4](6b29fe4)), closes [liuweiGL#58](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/58)
* support MacOS with M2 chip ([liuweiGL#67](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/67)) ([aebfd07](aebfd07))
* Support more platforms and architectures ([0cb9571](0cb9571)), closes [liuweiGL#68](https://github.com/skymoonya/rsbuild-plugin-mkcert/issues/68)
* support read host from server config ([305639b](305639b))
* Upgrade vite to 5.0 ([ac39d72](ac39d72))
* use peerDependence instead of dependence to control vite version ([542f15e](542f15e))
* 适配 v4.3.0 ([a117ed8](a117ed8))
* 适配 vite3.0 ([960ff59](960ff59))

### Performance Improvements

* pretty log formatter ([f75dfd1](f75dfd1))
* upgrade all dependencies ([fd5a8c0](fd5a8c0))
* upgrade dependencies version ([306f844](306f844))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants