Search code examples
yarnpkg-v2

preventing yarn from running in wrong directory


Sometimes I run yarn (2) in the wrong directory, which can result in the download of thousands of files. Cleaning that up takes a lot of time.

Is there an easy way to prevent yarn from running in a certain directory?

I am using Windows, by the way. But an OS independent solution would be even nicer.


Solution

  • I found this solution:

    1. In that directory create a subdirectory node_modules.
    2. Remove the right to write in that subdirectory for the relevant user(s).

    The result looks like this:

    > yarn add cypress      
    yarn add v1.22.15
    info No lockfile found.
    [1/4] Resolving packages...
    [2/4] Fetching packages...
    [3/4] Linking dependencies...
    error An unexpected error occurred: 
    "EPERM: operation not permitted, mkdir 'C:\\...\\node_modules\\ansi-escapes'".
    

    An nothing is downloaded into that node_modules.