npm install package from local folder - node.js

I am behind a firewall and I believe git connection at 9418 are getting blocked. So I want to install a repository via npm (mysam https://github.com/mysamai/mysam). I tried installing directly with
npm --proxy <proxy-details> install -g mysam
Which fails saying -
fatal: Unable to look up github.com (port 9418) (No such host is known. )
So to avoid that I downloaded zip of the git repository and found on internet to use
cd package-folder
npm link
However that also fails stating same error. Is there any option to install the locally downloaded repository.
Thanks

Using npm without an internet connection just does not work.
This is how we worked around this for a fully isolated node project:
You need a machine with internect connection. On this machine you do all the npm install calls.
Getting the installed files to other machines is easy if you are on linux or mac. With windows you are likely to have problems with long path names. Windows can handle them internally but almos all tools including windows explorer, winzip, 7-zip and friends cannot handle them. You have to use either robocopy or put everything into a git repo to move them arround. For GIT check https://stackoverflow.com/a/26111092/671639 to make it handle long path names on Windows. Also add the node_modles/**/bin/** folder to .gitignore.
We used GIT and moved around the repo. Attaching it as a remote allows to pull in new installed modules to the closed system.
Once the new module is available in your closed system call npm rebuild to make sure you have all the tooling availbable.
Of course this means to add node_modules to GIT or whatever SCM you are using.

Related

React app build fails in Docker in Jenkins, but not locally

On my local machine, npm run build works just fine. On my Docker image launched via Jenkins, I get issues like
Cannot find module: 'file-saver'. Make sure this package is installed.
You can install this package by running: npm install file-saver.
and
FAIL src/core/App.test.js
● Test suite failed to run
Cannot find module 'surface-nets' from 'vtext.js'
On my local machine, I have cleared the npm cache (npm cache clean -f), removed node_modules/, and reinstalled (npm i). I have even used npm update and the npm-check-updates package to update everything. I installed all peer dependencies. My local copy should be as wiped-clean as the copy within Docker is. In the Jenkinsfile, I put npm list and it shows surface-nets and file-saver and all my other packages. I also put ls node_modules/ and I can see the package folders are there. I have reduced my Dockerfile down to just 1 line: FROM node:current.
Why is it saying "Cannot find module" when the modules are installed?
The root cause of this issue is still unknown, but I did find out that the repository was corrupted. I ended up wiping the whole remote repo and git init-ing a new one, then pushing to that. I assume that corruption contributed to the issue at hand here.

How to run npm webpack vue project on both Windows and Mac?

I took a Vue 2 online course and it did show (but didn't really explain) how to install node.js, npm and vue. Currently using vue-cli to set up my project using vue init webpack-simple. Problem is I have a Windows desktop and a Mac laptop. I'm using Box cloud on both but I need to have 2 separate folders for the same project. Basically, project-1-windows and project-1-mac.
I can't run npm run dev on the project-1-mac while on Windows 10 and vice versa. The only way I know to run both is to delete the node_modules folder and run npm install. However it takes a while for the files to download. Is there an easier way to do this?
It looks like you want either GitHub/BitBucket/friends or (for much more complex set-ups) Docker.
I will explain only the first (easier) option. To set-up docker, you rather go to its docks.
So, for GitHub/BitBucket/friends way, you need some one-time set-up (you have to do all of this in terminal of your machine. I don't go too deep into details because you may find corresponding docks for each thing easily by googling it).
Install git if needed on both machines. On mac, you just run git --version in terminal. It'll either show the version of installed git or will ask if you want to install git together with other developer tools.
Install brew on Mac, install any of these on Windows. These are just package managers. Use them to install nvm.
Install nvm (it's node version manager, arguably the most convenient way to manage node.js installations) on both machines.
Use nvm to install node.js (npm comes bundled with it) on both machines. That's it! One-time set-up done. Run node -v && npm -v to check that both are installed.
Now, to start each project you would do the following:
Create a repo (which is like a folder but on GitHub/BitBucket server) that you may freely access from any device that has internet connection.
Start project on any of your machines with something like npm init or vue init webpack-simple or whatever you feel comfortable with.
Run git init
When you do changes, commit & push them into your online repo.
Avoid committing files that might be auto-regenerated, they simply don't worth storing.
You may use any npm commands.
When you want to continue working on another machine, simply git clone your existing repo, run npm install and you are done.
Commit changes if needed.
git pull changes to another device if needed

Installing Node packages globally without internet connection

I am working on Windows Server 2012 R2, but external internet connection is restricted in my Org. So i can not install any NPM packages on server directly.
I want to install pm2 OR forever packages globally so that all the user profiles(admin and users) can access that from any directory.
Please guide me in this case.
From another pc with internet connection, you can download the source code from github. For example, for pm2 it is : https://github.com/Unitech/pm2
After downloading the source code, you need to look into the package.json file and download all the dependency source code too. ( One easy way to do all of above is to use npm to fetch pm2 in a local directory then copy the pm2 along with all dependencies to a USB)
Transfer files into a directory of your server workstation using USB or any other suitable means.
Add the pm2/bin directory to your PATH.
Test with pm2 -v from command line to ensure PATH addition is correct.

Installing npm modules in a VM shared directory and grunt issues

I'm trying to put together a development environment and npm is causing me problems. Here is my scenario:
I have a development machine running Windows and VMWare Player. I have a Ubuntu Server VM (no UI) which is configured with Apache, PHP, NodeJS etc. As the VM has no UI I want to use the host OS for development. I set up a shared directory which in the VM is accessed as /mnt/hgfs/source/<project name>.
The problem comes when I attempt to run npm install within this directory. I see a lot of errors like Error: UNKNOWN, symlink '../requirejs/bin/r.js'. I know that my package.json file is OK because if I copy all files out of the share and into a regular unix directory (/var/www/<project name>) npm install works fine. So npm has a problem installing modules in the shared directory.
I thought I could get around this by installing the node packages globally but, for whatever reason, the GruntJS enthusiasts don't like that and it must be present locally. I then tried to create an npm link from global to local but that just results in a new error: Error: May not delete: /usr/lib/node_modules/grunt. I have full permissions on the /usr/lib/node_modules directory and all sub-directories.
I really don't want to write the entire project using a command-line text editor in the VM but it looks like I cannot have my code-base in a directory available to both the host and guest OS through VMWare.
I would very much appreciate any suggestions on how to either 1) allow npm modules to be installed in my shared directory, 2) run Grunt globally, or 3) solve the npm link error I'm seeing.
EDIT: Shortly after posting this I realised the fundamental issue here - it's not possible to create symbolic links within a VM shared directory when the host OS is Windows. As npm install uses symlinks by default it didn't work, and this is why the accepted solution does work.
Try the following:
npm install --no-bin-links
Grunt should be local since the plugins and gruntfile.js may require a certain version of Grunt in order to run your tasks. If another developer would like to run your tasks, they could just issue an npm install and they are set. (See this for more info.) grunt-cli is global which is used to run the local version of grunt

NPM throws errors at traceur install on OS X

https://github.com/tejas-manohar/itnerary-civic-hacking -- I cloned this git repo down locally. Installed grunt-cli globally, and ran npm run nss (script written by author of original server template -- look in package.json, not complex) and faced numerous errors at the traceur install + git cloning. I've included the trail from terminal window in the pastebin linked below. The npm debug/error log mentioned is not present at the suggested location. npm install alone does not help the situation and returns nothing back. NodeJS v0.10.29 is installed via Node Version Manager (NVM) on OS X 10.9.3.
http://pastebin.com/UJFL3k2E
I'm not the most adept with some of the technologies discussed here. Would someone please attempt to walk me through (a) solution(s) and/or steps to get better clues? All assistance is appreciated.
There's a couple of problems going on which are causing the problems you have seen. The first of which is the command that is run when you run npm run nss, which fails for you with this:
rm: ../../app/static/js/vendor/traceur.js: No such file or directory
This is because, well, the file simply does not exist (yet). If you look at the commands which are run when you run npm run nss, you'll see that the remove file is followed by the copy file of traceur.js to that very location. So I would guess that whoever wrote the script intended for this to be run after it was initially setup, and the remove/copy would be done once the file was initially copied there. Therefore, you must first copy the traceur.js file to app/static/js/vendor before you can successfully execute npm run nss.
But then the next problem, the file should be copied from tools/traceur-compiler/bin doesn't exist either. This is because the traceur-compiler project has recently deleted this (compiled) file from their project, which you can see via this commit: https://github.com/google/traceur-compiler/commit/429c3d850dcb7636320e81fd782c61a06de0fbf1
So you need to regenerate this file, which you can do by (from the itnerary-civic-hacking root directory):
cd tools/traceur-compiler
make bin/traceur.js
cp bin/traceur.js ../../app/static/js/vendor
This will get you in the same state as if you successfully ran npm run nss.
You won't be able to re-run the npm run nss command, but you really shouldn't need to since its more of a setup command than anything (it creates a directory, clones a github repo, etc). If you wanted to update the traceur-compiler in the future (though you may never have to do this) then I would recommend running the following steps (from the itnerary-civic-hacking root directory):
cd tools/traceur-compiler
git pull origin master
npm install
make bin/traceur.js
cp bin/traceur.js ../../app/static/js/vendor

Resources