How can we integrate Yarn in Phoenix for getting the node dependencies?

I’m on a very slow internet connection. While using Rails I used to run rails new myapp --skip bundle and after that I ran bundle install --local in the newly generated app’s directory. That’s how I could generate a new app even if my internet was very slow (or even not available sometimes).

Recently I was using React while Yarn was installed on my system, create-react-app detected Yarn and ran it instead of npm, so when next time I generated a new react app while my internet was very-slow/disconnected, create-react-app instelled all the dependencies from the local cache (through Yarn) which was amazing.

While generating a new phoenix application through mix, the elixir dependencies are installed from the cache if there is some problem with internet, ( I know that because I ran mix deps.clean and then mix deps.get while my internet was faulty at the moment, and I got results like :timeout, Failed to fetch record for 'hexpm/cowboy' from registry (using cache) ).

The only problem with generating a new Phoenix app is the node_modules which are installed through npm which doesn’t support getting dependencies from the local cache if the internet is slow, if we somehow replace npm with Yarn, this problem will be solved for people who are on slow or faulty internet connections.

I know some people will tell me to go to the assets folder and run yarn instead of npm install, and next time Yarn’s cache will be available for me. I tested that, but when the next time I ran yarn, it told me that there was no lockfile

(Note: In learning stage people run rails new or mix several times a day, so the modules/packages in cache are often recent, so that’s not a problem).

Phoenix is agnostic as to what front-end framework you want to use. It just comes with npm setup in the templates by default as that is generally what you have regardless of anything else, but you can of course use whatever you want.

Did you try --prefer-offline flag with npm install ?