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

[Bug]: yarn cap run fails with yarn 4 - SyntaxError: Unexpected token 'E', "Error: spawn ENOTDIR" #7285

Open
2 of 3 tasks
conlanpatrek opened this issue Feb 25, 2024 · 3 comments
Labels
cli priority: low type: bug A confirmed bug report

Comments

@conlanpatrek
Copy link

Capacitor Version

💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 5.7.0
@capacitor/core: 5.7.0
@capacitor/android: 5.7.0
@capacitor/ios: 5.7.0

Installed Dependencies:

@capacitor/ios: not installed
@capacitor/cli: 5.7.0
@capacitor/core: 5.7.0
@capacitor/android: 5.7.0

Other API Details

npm: 10.2.4
node: v21.6.1
pod: 1.11.3
yarn: 4.1.0

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

Detail and full reproduction is in the linked repo, but:

Init an empty repository with yarn 4 (making sure the output of yarn --version isn't 1.x.x)

Go through the "Getting started" guide here and here using yarn instead of npm.

Try running yarn cap run android and see the stack trace generated

Expected Behavior

I expect yarn cap run android to run the simulator, but it does not.

Project Reproduction

https://github.com/conlanpatrek/capacitor-yarn-bug

Additional Information

I've seen several ghosts of this same issue opened and closed in the past couple of years in this repo, basically since yarn 2, but a lot of them were hit-and-runs that never got resolved. Hoping the minimum recreation helps.

I'm running macOS 14.2.1.

@conlanpatrek
Copy link
Author

Following up. Are you having an okay time with the reproduction? Lmk if you need more info, or if yarn support > v1 is not on the table at all. I've already downgraded to work around the issue so I'm not hurting over here. 👍

@jcesarmobile jcesarmobile added cli type: bug A confirmed bug report labels Jun 25, 2024
Copy link

ionitron-bot bot commented Jun 25, 2024

This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.

@diegoflorez
Copy link

diegoflorez commented Oct 25, 2024

I've encountered the same issue with Capacitor CLI 6.x. It doesn't work well with Yarn 4.x (Berry) due to the Plug'n'Play (PnP) system. However, I've found three workarounds that successfully resolve the problem:


  1. Switch to Node Linker: By setting Yarn to use the traditional node_modules structure, Capacitor works correctly. You can enable this by running:
yarn config set nodeLinker node-modules

After setting this, you will need to execute:

yarn install

And finally, it will execute correctly with:

yarn cap run android

  1. Open and Run the Project in Android Studio: Even if yarn cap run android fails, you can still open and run the project using Android Studio by executing the following command:
yarn cap open android

This opens the project in Android Studio, and it runs without issues from there.


  1. Add native-run as a Dev Dependency and Unplug It: If you prefer to keep Yarn's Plug'n'Play enabled, another solution is to add native-run as a dev dependency and then unplug it. This ensures that native-run behaves like it's in a traditional node_modules structure while keeping the rest of the project in PnP mode.

First, add native-run as a dev dependency:

yarn add native-run --dev

Then, unplug native-run:

yarn unplug native-run

Finally, install your dependencies:

yarn install

This way, Capacitor will work correctly without needing to switch to node_modules for the entire project.

I hope this helps others facing the same issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli priority: low type: bug A confirmed bug report
Projects
None yet
Development

No branches or pull requests

3 participants