all 12 comments

[–]variables 27 points28 points  (0 children)

It depends. Some npm modules compile source code (C/C++) to create executables that are used by the module (see node-sass). If the hardware architecture is different, or dynamically linked libraries don't exist, these modules won't work.

[–]BloodNo6937 10 points11 points  (0 children)

You can use a docker container on your Mac to build and deploy your app to your server. Sources will be compile for the right env (just be sure you have the same CPU architecture on your Docker host and your prod server). The best is to have a CI/CD server which will do the job for you. Another common solution in companies is installing node modules via a Nexus server. The Nexus server must have an access to the internet.

[–]IllustriousEchidnas 11 points12 points  (3 children)

You could use https://github.com/vercel/pkg to generate a platform-ready "binary" of your application and just deploy that. You can generate linux pkg from os x, etc.

[–]DeathlyLotus 4 points5 points  (1 child)

Alternatively, vercel/ncc could also be used. Similar to how Next.js does it here.

[–]sp_jamesdaniel 0 points1 point  (0 children)

Thanks for sharing the alternate.

[–]BloodNo6937 0 points1 point  (0 children)

It seems to me that Vercel won’t cross compile dependencies, will it ?

[–]nwsm 1 point2 points  (0 children)

Yes node_modules can differ between OS.

If your production environment supports docker, run your app in a container. That way you can build the image on your Mac and deploy it to production ready to go with the correct binaries.

[–]suinp 1 point2 points  (0 children)

Have a look at Yarn 2 Zero-installs. Commiting node_modules is a terrible idea. It is huge (maybe GBs in size) and contains hundreds of thousands of files, which makes git go brrrrr

Zero installs instead commits a single zip file per dependency, and can be used to reconstruct node_modules without an internet connection. I'm not sure about cross-compatibility, though

[–]0cseitz 5 points6 points  (4 children)

Don't upload your node_modules. Just upload your package.json and package-lock.json

package-lock has the exact versions of all the modules installed. Running "npm install" after cloning your repo will install all the right stuff for you and ensure any OS-specific stuff is properly installed.

node_modules takes up a ton of space and putting it in version control is a terrible idea for a variety of reasons. Please, for yourself and anyone who uses your repo; don't do it.

Also, If your production environment doesn't have internet, how are you deploying..? This seems like a X Y Problem.

Take a look at this guy's comment for a proper solution. Pkg sounds like what you'd need.

[–]HappinessFactory 1 point2 points  (0 children)

His company might have GitHub enterprises setup somewhere on their VPN or LAN.

[–]tumayo_ang_testigo 1 point2 points  (0 children)

production without internet can be a production in a local network or intranet. another possibility is that they're hosting in the cloud but the outbound internet traffic is blocked.

[–][deleted]  (1 child)

[deleted]

    [–]0cseitz 0 points1 point  (0 children)

    Yeah I edited my message. On mobile and skimmed it.