Why does yarn install checkout a github repository dependency but npm install does not? - node.js

I'm listing a github repository (TypeScript project if it matters) as a dependency in package.json:
"ethereumjs-vm": "git+https://github.com/ethereumjs/ethereumjs-vm.git#v4.0.0-beta.1"
I want to extend some of the classes of this public project in my own project. With yarn install the whole repository gets checked out/copied (not a real git clone, since I can't run git commands) into node_modules/ethereumjsvm which is fine.
With npm install https://github.com/ethereumjs/ethereumjs-vm/tarball/v4.0.0-beta.1
--save the code gets checked out too.
With npm install I only get 4 files in node_modules/ethereumjsvm: changelog, license, package.json and readme.
What's the difference? Why does npm install does not get the source code from the repository?

Aaron Bell provided me with the answer: The files property in the package.json of the github project I want to include only contains the dist folder:
"files": [
"dist/**/*"
]
This means npm install will ignore all other files in the repository (except changelog, license, package.json and readme which are always installed, see package.json files docs). yarn seems to have a bug where this files property is ignored (issue).
After this I tried npm installwith a project from github without a files property in package.json and it worked - the source code was stored in node_modules.

Related

How to switch from default npmjs repo to Artifactory repo in Angular project

I'm developing an Angular application and until now I have been using the default npm repository (registry.npmjs.org). Now I need to switch to using Artifactory and update my project accordingly.
I already changed the registry with:
npm config set registry (myArtifactoryRemoteRepoURL)
Then, after deleting the nodes_module folder I ran the npm install command:
npm i
I also tried:
npm i --package-lock
The modules are still loaded from the default npmjs registry. I guess this is because in the package-lock.json the dependencies are still resolved to default repo URLs. So I would probably have to update the package-lock.json somehow.
You can delete the package-lock.json file entirely (and the node_modules as well). Those will be regenerated when you run npm install.

Can I copy the remote folder of node mudules on git lab?

The node module that I need has been updated, and there is an old version of it installed on the gitlab project. Is it possible to get the folder for that specific module as it is when it was installed?
Thank you
You dont't want to keep source code of external dependencies in your repo. You should add your node_modules to .gitignore and remove it from the repo. Instead, you just track your dependencies in your package.json file by installing them via npm install --save. Then, when someone checks out your project, he just runs npm install and all dependencies get resolved automatically. If you want to update any of the dependencies, you update it via npm cli, and commit the updated package.json to your repo.

Why do some github npm packages not fully install?

I was trying to install this npm package from its github repo using this command:
npm install --save github:kpdecker/jsdiff
It looked like it went okay, because the diff folder got created inside node_modules but it didn't contain the lib or dist folders and none of its dependencies got installed. These were the only files that get copied:
runtime.js
release-notes.md
package.json
README.md
LICENSE
CONTRIBUTING.md
However, the command above works perfectly when installing other packages. For example:
npm install --save github:visionmedia/express
So, what am I missing. Is there some other command that I'm supposed to run to complete the installation of jsdiff?
This package needs a build step (see the gruntfile.js). So the artifacts (the files that will be generated at the build step wont be checked in the versioning system - git - you wont have to deal with them in your diffs and merge).
Also check out the .npmignore file.

What is the proper way to deal with node_modules in git?

I am a beginner with git and node. So I created a new repository in git, and installed react and babel, and git is telling me that the repository is too large. Literally all I did was run something like this:
created index.html
created app.js
> npm init (initialized package.json)
> npm install --save react react-dom
> npm install --save-dev babel_preset_react
> npm install --save-dev babel_preset_es2015
added babel config to package.json
Maybe I'm missing something, but I haven't even built anything yet, and I'm already getting complaints that my repo is too large. Git desktop is even throwing OutOfMemory exceptions! So I wondered, maybe I'm not supposed to check in the node_modules folder. Then I read this:
https://web.archive.org/posts/nodemodules-in-git.html
But I am even more confused now. The article says you should check in node_modules for projects that you deploy. But doesn't that mean it's still going to be a "large repository?"
At the bottom, the article says not to add node_modules to gitignore. I think gitignore just ignores the files in that folder from being committed to git. So is this telling us to not ignore node_modules? As in, check-in node_modules?
And what is that $ npm rebuild on deploy?
As a beginning to npm and git, can someone explain what I should do in simpler terms?
I just checked the link you shared is broken. We never check-in node_modules to repositories they easily add LOT of MBs to the overall size. Please add the node_modules in .gitignore. You should only checkin package.json to your repository. This is how my .gitignore in AngularJs project looks like,
.idea
node_modules
dist
npm-debug.log*
.DS_Store
If you are worried about the breaking changes due to version upgrade please specify the "~" sign in front of the version no. of packages (package.json) so only the patches will be considered.
Ex.,
"angular": "~1.5.6"
you don`t need to push node_modules into your repo . Add node_modules to gitignore and when you deploy your code on the server you have to install node_modules over there using command :
npm install
As your package.json is updated when you locally install node_modules and it is pushed to repo . When you run npm install on the server , all your packages will be installed which are mentioned in package.json

npm to install packages from local position rather than from web?

The problem drove me crazy, there is a package in npm database, but it has some bugs, which are already fixed in github, how could I make use of the fixed version(github version)?
Edit:
You can install directly from the GitHub repository, even just using the GitHub username and the repository name:
npm install LearnBoost/socket.io
You can also add a <commit-ish>, specifying e.g. a commit hash or a version tag, like so:
npm install LearnBoost/socket.io#1.7.x
Without a protocol, this will be interpreted as git://github.com/LearnBoost/socket.io. You can also prefix the repo with gitlab:, gist: or bitbucket:, respectively. For more information, see Using git URLs as dependencies.
You can install directly from a URL, example:
npm install https://github.com/LearnBoost/socket.io/tarball/master
You can find the URL on Github under "Downloads" on any project page. Select the "Download as tar.gz" link.
Or you can install a tarball:
npm install foo.tar.gz
See npm install(1).
Edit:
I should mention that this works equally well in package.json files. Specify the URL instead of the version in your dependencies, like so:
...
"dependencies": {
"foo": "http://example.com/foo.tar.gz",
"bar": "1.2.x",
...
}
Other temporary solution, get the github project and use npm link (http://npmjs.org/doc/link.html) to link the local folder obtained through git to your node_modules folder in your own project. Anyway in the end, you'll have to wait for the project maintainer to do a npm publish.
Either add the module as a git sub-module (using git submodule) to your project or tell the module maintainer to update the version and trigger a npm publish to update the npm repository.
When using the sub-module way, be aware that you cannot update the reference using npm-commands.

Resources