skip to Main Content

I have a web app located under C:Google-drivevue-app. Running yarn build command will install node_modules folder in C:Google-drivevue-app. I am using Google Drive to sync my web app source code to Google cloud. The problem I am facing is the thousands of files in node_modules will crash Google Drive.

Is there some way to configure package.json to install node_modules folder outside of C:Google-drivevue-app and have it installed in a location called C:tempnode_storage?

I am open to any solution that can stop Google Drive from syncing node_modules folder. It need not necessarily involve configuring package.json

2

Answers


  1. It looks like there are a few options suggested over at Excluding node_modules folders from syncing with Google Drive.

    Replacing node_modules with a symbolic link looks to be the simplest.

    I know Dropbox has an undocumented method using an alternate file stream that can be done in Windows to avoid syncing certain folders. I use this batch script to set the alternate file stream:

    @echo off
    
    REM This script should be executed from the root of the repo
    REM Folders which potentially can become large (node_modules, logs, etc) will be created
    REM then a stream file created that instructs the Dropbox service to keep the folder locally, but not sync to the cloud
    set repoRootPath=%cd%
    
    REM Back Folders:
    mkdir %repoRootPath%backnode_modules
    echo 1 > %repoRootPath%backnode_modules:com.dropbox.ignored
    
    mkdir %repoRootPath%backlogs
    echo 1 > %repoRootPath%backlogs:com.dropbox.ignored
    
    
    Login or Signup to reply.
  2. I don’t think it’s possible to configure package managers like that. The only reason I purchased Insync was so my node_modules folders would not be synced to cloud services like Google drive or Dropbox.

    Insync supports ignore rules: https://www.insynchq.com/i/features/ignore-rules

    Ignore rules works like .gitignore

    Set rules for files or folders you don’t want to sync.
    … node_modules, anyone?

    Insync works very well. Overall the experience is much better than having node_modules constantly and needlessly syncing to the cloud.

    Sometimes the sync gets a little janky after removing or adding a whole bunch of files suddenly (like npm install). Other times git gets confused because files seem like they were modified, but they were just deleted and recreated by sync. (A simple git add . resolves this.)

    Also at first the Insync UI can be a little confusing to get set up correctly. There are just a lot of features I don’t need like two-way vs. one-way cloud sync. But once it’s set up, it works automatically. So you can pretty much forget about it.


    A bonus feature of Insync is I can move my git projects outside the folder (and even drive) limitations dictated by Google Drive/Dropbox. For example:

    • My git projects are synced to c:dropboxp

    • Insync lets me work with my projects from s:p (I think a bare drive like p: is also possible.)

    • (I configure Dropbox not to sync c:dropboxp so I only have one copy synced locally)


    Before that, I was using this script to tell Dropbox not to sync node_modules folders. But it only applies to existing folders, so must be repeated if new node_modules folders are created:

    ignore_node_modules.sh

    #!/bin/sh
    
    find "$1" -type d | grep 'node_modules$' | grep -v '/node_modules/' | xargs -I {} -t powershell -command "Set-Content -Path '{}' -Stream com.dropbox.ignored -Value 1"
    

    See this question for more details about the script above: https://stackoverflow.com/a/69655523/117030 (I used git-bash for windows, thus the mix of bash and powershell.)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search