Skip to content

npm install fails when "Extension Pack for Java" is enabled in vscode/cursor #66662

Closed

Description

@chuckdries

This is a build issue. It does not affect users, but may prevent contributors from being able to run and test the code.

Version Number:
Reproducible in staging?:
Reproducible in production?:
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @chuckdries
Slack conversation (hyperlinked to channel name): #expensify-open-source

Action Performed:

  1. Checkout App repo
  2. open in Cursor
  3. install https://marketplace.cursorapi.com/items/?itemName=vscjava.vscode-java-pack extension (or vscode equivalent) and enable it
  4. attempt to run npm install

Expected Result:

Install succeeds and exits

Actual Result:

Install fails on patch-package

**ERROR** Failed to apply patch for package react-native-vision-camera at path

    node_modules/react-native-vision-camera

  This error was caused because patch-package cannot apply the following patch file:

    patches/react-native-vision-camera+4.6.1.patch

  Try removing node_modules and trying again. If that doesn't work, maybe there was
  an accidental change made to the patch file? Try recreating it by manually
  editing the appropriate files and running:

    patch-package react-native-vision-camera

  If that doesn't work, then it's a bug in patch-package, so please submit a bug
  report. Thanks!

    https://github.com/ds300/patch-package/issues




  - Failed to apply patch file: /Users/chuckdries/Expensidev/App/patches/tmp-patches-uYN/react-native-vision-camera+4.6.1.patch
---
patch-package finished with 2 error(s).

💥 patch-package failed
npm error code 1
npm error path /Users/chuckdries/Expensidev/App
npm error command failed
npm error command sh -c ./scripts/postInstall.sh
npm error A complete log of this run can be found in: /Users/chuckdries/.npm/_logs/2025-07-16T22_12_46_920Z-debug-0.log
Dependency installaton failed. Check if package-lock.json exists

If you run npm install another time, it'll also fail for @onfido/react-native-sdk

Workaround:

N/A, tooling issue does not affect users

Platforms:

N/A, tooling issue does not affect users

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @marcaaron

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jul 17, 2025
  2. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jul 17, 2025
  3. melvin-bot commented on Jul 17, 2025

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @ikevin127 (External)

  4. melvin-bot commented on Jul 17, 2025

    @melvin-bot

    Triggered auto assignment to @isabelastisser (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  5. TaduJR commented on Jul 18, 2025

    @TaduJR
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    npm install fails when the "Extension Pack for Java" is enabled in VS Code/Cursor. Developers are forced to either disable Java extensions entirely or manually work around the installation failures, disrupting their development workflow and preventing them from using Java tooling alongside the React Native project.

    What is the root cause of that problem?

    The Java extensions in VS Code/Cursor automatically scan and process files in node_modules during package installation. This creates a timing and file state conflict with patch-package:

    1. During npm install: Fresh packages are downloaded to node_modules in their original state
    2. Java extensions activate: They immediately scan node_modules and modify/create metadata files for Java/Android components (especially in React Native packages like react-native-vision-camera)
    3. patch-package runs: Expects files to be in their exact original state but finds them modified by Java extensions
    4. Patch application fails: patch-package detects file differences and refuses to apply patches, causing the entire installation to fail

    This happens because patch-package uses binary/checksum comparisons and expects pristine file states, while Java extensions continuously modify files for indexing and IntelliSense purposes.

    What changes do you think we should make in order to solve the problem?

    Primary Solution: Configure VS Code Workspace Settings

    Create a .vscode/settings.json file with the following configurations:

    {
        "java.project.resourceFilters": ["node_modules/**", ".git/**"],
        "java.import.exclusions": ["**/node_modules/**", "**/.git/**"],
        "java.project.sourcePaths": [],
        "files.exclude": {
            "**/node_modules/**": true
        },
        "search.exclude": {
            "**/node_modules/**": true
        }
    }

    Benefits of this approach:

    • Keep Java extensions enabled - No functionality loss for Android development
    • Zero workflow disruption - Developers can continue using Java tooling
    • Automatic solution - Works transparently once configured
    • Performance improvement - Java extensions won't scan large node_modules directories
    • Universal compatibility - Works across VS Code, Cursor, and other editors

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    1. Test npm install with Java extensions simulation

      • Create a test that simulates Java extension file modifications during installation
      • Verify that patch-package can still apply patches successfully
      • Test with both clean installs and incremental installs
    2. Test workspace settings effectiveness

      • Verify that .vscode/settings.json configurations properly exclude node_modules
      • Test that Java extension scanning is actually prevented in the configured directories
      • Validate that actual Java source files are still properly processed
    3. Test patch application robustness

      • Create scenarios where files have minor modifications (whitespace, metadata)
      • Verify the enhanced applyPatches.sh script can handle these gracefully
      • Test with different types of patches (React Native, native modules, etc.)

    What alternative solutions did you explore?

    1. Complete Java Extension Disabling

      • Pros: Guaranteed to prevent interference
      • Cons: Loses all Java development functionality, major workflow disruption
    2. Modifying patch-package Timing

      • Pros: Could potentially avoid conflicts
      • Cons: Complex to implement, doesn't address root cause, fragile solution
    3. Using npm ci instead of npm install

      • Pros: Faster, more predictable installs
      • Cons: Doesn't solve the underlying issue, still fails with Java extensions

    Result: https://www.loom.com/share/75ab9ef0873b480abb269546e9387325

  6. ikevin127 commented on Jul 19, 2025

    @ikevin127
    Contributor

    @chuckdries Followed steps to the letter (using Cursor, installed the exact same extension), then ran both npm install and npm ci and I can't reproduce the issue at all, I always get success on patch-package:

    +    🎉 patch-package succeeded without errors or warnings

    @TaduJR Thanks for the proposal. Regarding the suggestion to add .vscode/settings.json publicly to the repository, basically unhidding the .vscode editor settings from .gitignore, IMO we shouldn't do this as it pretains to the user's local settings which should not be enforced for everybody.

    This shouldn't be an issue IMO, as editor specific issues should be fixed locally by the people experiencing them, especially with very specific edge cases like using a paid code editor and having a specific extension installed. I don't see such issues as a problem caused by the Expensify/App repo, hence requiring an issue to fix the problem for everybody (since most don't use the same code editor / extensions causing the issue).

    At most, I'd post a public message in Slack to let everybody know that in case they are experiencing issues with patch-package failing, it might be due to their code editor / extensions (since 99% of the people are not experiencing the issue) and could most likely fix the issue by adjusting their local .vscode/settings.json.

    🎀👀🎀 C+ reviewed

  7. melvin-bot commented on Jul 19, 2025

    @melvin-bot

    Triggered auto assignment to @marcaaron, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

  8. TaduJR commented on Jul 20, 2025

    @TaduJR
    Contributor

    Awesome @ikevin127

    That's great solution since most people are not experiencing them.

    Thank you so much for your feedback.

  9. chuckdries commented on Jul 21, 2025

    @chuckdries
    ContributorAuthor

    Huh, I can't reproduce the issue anymore. Oh well I guess

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributorsReviewingHas a PR in review

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions