ionic-team / ionic-cli

The Ionic command-line interface
MIT License
2k stars 654 forks source link

Incompatible option for yarn v2 #4483

Open psydvl opened 4 years ago

psydvl commented 4 years ago

Description: ionic start command broken with Yarn v2 (aka berry).

Steps to Reproduce:

$ yarn set version berry
$ echo n | ionic start Test blank --type=angular

Or even:

$ yarn set version berry
$ echo n | yarn dlx -p @ionic/cli ionic start Test blank --type=angular

Output:

> yarn install --non-interactive
Unknown Syntax Error: Unsupported option name ("--non-interactive").

$ yarn install [--json] [--immutable] [--immutable-cache] [--check-cache] [--inline-builds]
[ERROR] An error occurred while running subprocess yarn.

        yarn install --non-interactive exited with exit code 1.

        Re-running this command with the --verbose flag may provide more
        information.

My ionic info:

[WARN] You are not in an Ionic project directory. Project context may be missing.
Ionic:
   Ionic CLI : 6.10.1
Utility:
   cordova-res : not installed
   native-run  : not installed
System:
   NodeJS : v14.5.0
   npm    : 6.14.5
   OS     : Linux 5.7

Other Information: Migration guide: https://yarnpkg.com/advanced/migration

jay-babu commented 2 years ago

any update on this issue?

Andorbal commented 2 years ago

I just ran into this issue as well. Is there a workaround or is the Ionic cli currently unusable with Yarn Berry?

Andorbal commented 2 years ago

In case it helps anyone, I got a workaround going by temporarily changing the package manager back to npm in ~/.ionic/config.json, then running ionic capacitor add ios to add the iOS project. After that, I switched back to yarn and ran yarn install in the app directory (which removed the node modules folder). I was not able to run ionic capacitor open ios after that, but yarn capacitor open ios seems to work. That made me wonder if running yarn capacitor add ios would have worked, but I'm past that now :)

-- UPDATE -- Turns out, my original approach didn't work because it seemed to use Capacitor v2 to create the iOS project, which didn't work because it was expecting files to be in the node_modules folder, which doesn't exist. My package.json file had Capacitor v3 listed, which doesn't use npm packages for native files. So I removed the iOS folder created by my original command and ran yarn capacitor add ios and that worked: I was able to open the project in Xcode and was able to build and run it in the simulator. Whew...

wmadden commented 2 years ago

Any update here?

Losses commented 2 years ago

2 years later...

Losses commented 2 years ago

A pull request was made to fix this issue...

Losses commented 2 years ago

So, it seems nobody care about yarn berry, if you are facing this problem, simply create a patch file on .yarn/patches/@ionic-cli-npm-6.20.1-53fb01ed2a.patch, the content should be:

diff --git a/lib/utils/npm.js b/lib/utils/npm.js
index 640e88d400afdeef85b3859e02eaad97f5c29b9f..4443315d2fbfeeca941ca9cb1cf8b7a474b8170c 100644
--- a/lib/utils/npm.js
+++ b/lib/utils/npm.js
@@ -42,7 +42,7 @@ async function pkgManagerArgs(npmClient, options) {
             vocab = { run: 'run', install: 'i', bareInstall: 'i', uninstall: 'uninstall', dedupe: 'dedupe', rebuild: 'rebuild', global: '-g', save: '--save', saveDev: '-D', saveExact: '-E', nonInteractive: '', lockFileOnly: '--package-lock-only' };
             break;
         case 'yarn':
-            vocab = { run: 'run', install: 'add', bareInstall: 'install', uninstall: 'remove', dedupe: '', rebuild: 'install', global: '', save: '', saveDev: '--dev', saveExact: '--exact', nonInteractive: '--non-interactive', lockFileOnly: '' };
+            vocab = { run: 'run', install: 'add', bareInstall: 'install', uninstall: 'remove', dedupe: '', rebuild: 'install', global: '', save: '', saveDev: '--dev', saveExact: '--exact', nonInteractive: '', lockFileOnly: '' };
             if (options.global) { // yarn installs packages globally under the 'global' prefix, instead of having a flag
                 installerArgs.push('global');
             }

Then, change your version code of @ionic/cli in package.json with: patch:@ionic/cli@npm:6.20.1#.yarn/patches/@ionic-cli-npm-6.20.1-53fb01ed2a.patch.

run yarn to apply the patch, your @ionic/cli will play well with Yarn Berry, just like a magic.

Good luck and have a nice day.