ionic-cli icon indicating copy to clipboard operation
ionic-cli copied to clipboard

Don't use `--` when the `npmClient` is `pnpm`

Open NatoBoram opened this issue 2 years ago • 0 comments

Description:

When running ionic capacitor run android --livereload --external, I get an endless loop of [INFO] Waiting for connectivity with pnpm...

> pnpm run ionic:serve -- --host=0.0.0.0 --port=8100
[pnpm] > [email protected] ionic:serve /home/nato/Code/github.com/Omerlo-Technologies/theia-mobile
[pnpm] > vite dev "--" "--host=0.0.0.0" "--port=8100"
[pnpm]   VITE v4.3.9  ready in 474 ms
[pnpm]   ➜  Local:   http://localhost:5173/
[pnpm]   ➜  Network: use --host to expose
[pnpm]   ➜  press h to show help
[INFO] Waiting for connectivity with pnpm...
[INFO] Waiting for connectivity with pnpm...
[INFO] Waiting for connectivity with pnpm...

The issue is that pnpm run ionic:serve -- --host=0.0.0.0 --port=8100 doesn't work as expected because of that -- in the middle. -- is useful when you want npm to pass additional command-line arguments to scripts, but pnpm isn't limited by this restriction and it passes the whole thing. When vite receives that, it ignores everything after it.

This can be tested:

❯ vite dev --host=0.0.0.0 --port=8100

  VITE v4.3.9  ready in 527 ms

  ➜  Local:   http://localhost:8100/
  ➜  Network: http://192.168.1.213:8100/
  ➜  Network: http://192.168.1.214:8100/
  ➜  press h to show help


❯ vite dev -- --host=0.0.0.0 --port=8100

  VITE v4.3.9  ready in 519 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h to show help

Steps to Reproduce:

  1. Have a Vite app (ex: SvelteKit)
  2. Setup Capacitor and Ionic
{
	"name": "Hello World",
	"integrations": {
		"capacitor": {}
	},
	"type": "custom",
	"npmClient": "pnpm"
}
  1. Set these scripts in package.json
"dev:android": "ionic capacitor run android --livereload --external",
"ionic:serve": "vite dev",
  1. Run pnpm dev:android

Output:

My ionic info:

Ionic:

   Ionic CLI : 7.1.1 (/home/nato/.local/share/pnpm/global/5/.pnpm/@[email protected]/node_modules/@ionic/cli)

Capacitor:

   Capacitor CLI      : 5.0.5
   @capacitor/android : 5.0.5
   @capacitor/core    : 5.0.5
   @capacitor/ios     : 5.0.5

Utility:

   cordova-res : not installed globally
   native-run  : not installed globally

System:

   NodeJS : v20.2.0 (/usr/bin/node)
   npm    : 9.7.1
   OS     : Linux 6.2

Other Information:

Admittedly, this could be seen as a vite issue, but I it's possible that they would consider rejecting everything after -- as a security benefit.

NatoBoram avatar Jun 13 '23 18:06 NatoBoram