Installing npm packages offline from downloaded GitHub repositories

I’m having trouble using npm install for a package I got from GitHub. My work doesn’t let me connect to the npm registry directly. I downloaded the zip file for react-bootstrap-table2 from GitHub and tried to install it manually. But it’s not working right.

Here’s what I did:

  1. Downloaded the zip from GitHub
  2. Unzipped it and placed the folder in my project’s node_modules
  3. Tried to use the package, but encountered errors

Is there a way to make npm install work with this downloaded folder? I can’t use yarn either.

I read that my issue might be due to a lack of access to the npm registry, even though I can download from GitHub.

// For example, I'm trying this command
npm install ./local-react-bootstrap-table2-folder

// But it doesn't register the local folder as a valid package

Any suggestions on how to resolve this would be appreciated.

hey mate, ive been in ur shoes. try this: npm install file:./local-react-bootstrap-table2-folder. it tells npm to use the local folder as a package. make sure theres a valid package.json in there tho. if that dont work, u might need to manually install the dependencies listed in the package.json. its a pain but sometimes necessary in locked-down environments. good luck!

I’ve run into similar issues with offline npm installs before. One trick that worked for me was using the file: protocol when installing from a local directory. Try this command:

npm install file:./local-react-bootstrap-table2-folder

This tells npm to treat the local folder as a package directly. Make sure the folder has a valid package.json file though.

Another approach is to create a tarball of the package first:

cd local-react-bootstrap-table2-folder
npm pack
cd ..
npm install ./local-react-bootstrap-table2-folder/react-bootstrap-table2-x.x.x.tgz

This mimics how npm usually installs packages and can solve some dependency issues.

If those don’t work, you might need to manually install the package’s dependencies listed in its package.json file. It’s a bit tedious, but sometimes necessary in restricted environments.

Hope this helps! Let me know if you need any clarification on these steps.

Having worked in environments with restricted internet access, I can relate to your situation. One approach that has worked well for me is creating a tarball of the package along with its dependencies. On a machine with internet access, clone the react-bootstrap-table2 repository and run npm install in the directory to fetch all necessary dependencies. Then run npm pack to create a tarball, transfer the resulting .tgz file to your work machine, and install it using npm install /path/to/react-bootstrap-table2-x.x.x.tgz. This method typically includes all required dependencies. If issues persist, you may need to repeat the process for any missing modules. Alternatively, setting up a local npm registry like Verdaccio on an accessible server within your work network can simplify offline package management.