3

I work in company that has some corporate proxy. I am able to install nodejs but I cannot install any npm module at all. I tried alot things, different proxy settings but none of them worked. Nodejs simply can't connect to internet to fetch modules I need. Basically Im trying to setup Cordova and Ionic on this computer.

I was wondering if there any way to offline install it? I meant, is there any way to bring these files in USB drive or something and then install it?

It is possible or not?

Thank you Guys :)

Amrit Sohal
  • 77
  • 2
  • 9

4 Answers4

3

Yes, you can use Yarn to install packages without an internet connection.
For example, to install ionic and cordova globally:

  1. On the internet machine (configure local cache location):

    yarn config set yarn-offline-mirror ~/yarn-offline-mirror/
    
  2. On the offline machine (configure local cache location):

    yarn config set yarn-offline-mirror ~/yarn-offline-mirror/
    
  3. On the offline machine, Find out where is the global installation location:

    yarn global bin
    

    (Or set it with yarn config set prefix <file_path>)

  4. On the offline machine, add it to your path. E.g.:

    echo 'export PATH=$PATH:'"$(yarn global bin)" >> ~/.bashrc  
    source ~/.bashrc # reload
    
  5. On the internet machine, download ionic's and cordova's dependencies:

    mkdir new-cli-ionic-cordova/
    cd new-cli-ionic-cordova/
    yarn add ionic cordova
    

    Then copy new-cli-ionic-cordova/yarn.lock and ~/yarn-offline-mirror/ to the offline machine. (rm -rf new-cli-ionic-cordova/ is ok now.)

  6. On the offline machine, install ionic and cordova from local cache:

    cp /path/to/imported/yarn.lock .
    cp -n /path/to/imported/yarn-offline-mirror/* ~/yarn-offline-mirror/
    yarn global add --offline ionic cordova
    rm -f ./yarn.lock
    

You can also install packages as dependencies for a single project using a similar process. For more info, see my post here: https://assafmo.github.io/2018/04/11/yarn-offline.html

assafmo
  • 1,047
  • 3
  • 15
  • 32
  • For me, the blogpost contains the correct steps but the answer itself does not; perhaps you updated the blogpost and forgot to come back? You don't mention the package.json file here, and I can confirm it is necessary. – TamaMcGlinn Nov 23 '20 at 14:41
0

first I would try to get the npm-config working for your proxy. Talk to your IT how to connect to the https://www.npmjs.com/package/ registry. Probably these links can be helpful (just in case you didn't find them yet):

Probably you can post the logging output and someone can help you.

Only if this fails, I'd think about setting up a local package registry. Probably Sinopia can help you. But...:

  • A) When your IT won't allow you to connect to the official registry via network, why should they allow you to do so via USB?
  • B) This would introduce lots of work overhead to keep the your local package registry in sync with the official registry. And this effort obviously has to happen outside your workplace.

Any other thoughts?

Community
  • 1
  • 1
Konstantin A. Magg
  • 1,106
  • 9
  • 19
  • I tried all the proxy config settings given in link but none of them worked. Im sure our IT team wouldn't bother about this as this is something I wants to do for myself just a hobby.... I thought I could be sneaky about it and install whole thing without internet.but clearly it doesn't seems feasible. Thank you for your solution above. Appreciate it – Amrit Sohal Mar 12 '17 at 10:52
  • Regarding question A - it's quite common that the IT has rolled out aggressive content scanning and blocking that makes installing anything from the internet impossible, because the proxy messes with the content too much. So that the IT themselves need the USB solution to keep the company running... – 576i Oct 01 '20 at 09:03
  • Hi @576i, you mean: Instead of installing from origins with signed + trusted certificates your IT prefers sourcing from random + hard-to-validate USB devices? Doesn't that put the whole company network at risk? – Konstantin A. Magg Oct 02 '20 at 11:44
0

You can get npm to work behind a proxy to solve the problem. For this, it is important to set both HTTP_PROXY and HTTPS_PROXY environment variables.

For HTTP_PROXY you can use

npm config set proxy http://proxy_host:port

For HTTPS_PROXY you can try this one

 npm config set https-proxy http://proxy.company.com:8080
Abdul Alim Shakir
  • 1,128
  • 13
  • 26
0
  1. offline install nodejs:

step1: download nodejs: https://nodejs.org/en/download/

step2: tar xvf node-v16.17.0-linux-x64.tar.xz

step3: add to env:

vim /etc/profile.d/nodejs.sh:
#!/bin/sh
export PATH=/YOUR-PATH-TO/node-v12.16.2-linux-s390x/bin:$PATH

or 

vim ~/.bash_profile:
export PATH=/YOUR-PATH-TO/node-v12.16.2-linux-s390x/bin:$PATH
  1. offline install npm packages or node_modules:

method 1:

on machine A which has internet access:
npm install all the packages needed
upload the node_modules/* to /YOUR-PATH-TO/node-v12.16.2-linux-s390x/lib/node_modules/

method 2:

on machine A which has internet access:
>npm install -g npm-bundle
>npm install -g eslint
>npm-bundle eslint
eslint-7.8.1.tgz
on the target machine which has no internet access:
>npm install -g ./eslint-7.8.1.tgz

refer to js overview

LIU YUE
  • 1,593
  • 11
  • 19