i'm making a custom package for a project that i'm making, but it requires typescript to be installed as a local dependency...
npm i typescript #types/node ts-node ts-node-dev
This installs it in a node_modules folder, as per usual. The problem is though is when i try to locally install the package...
npm i ../package
it automatically creates a node_modules folder, and then installs it there. The package is installed inside a node_modules folder, within a package folder, within another node_modules folder.
My question is: how do i install it in the parent node_modules folder as a dependency alongside the custom one?
Related
I am trying to follow with pluralsight tutorial and he wrote npm install on the terminal, then a file called npm module is installed on the folder he specified. when I try to install npm this appears to me in the terminal, and the directory which Im trying to install npm on it contains only one document called package-lock.json enter image description here
npm install uses the package.json to install the necessary packages
I can see when you ls, there's no package.json in the directory, just the package-lock which is created where ever you run npm install
Make sure you run the npm install from the same directory the package.json in contained in
the problem is solved, I think that I download the web-dev-starter folder twice by mistake.
I am installing nodejs module(jasmine-ajax) in my local machine . I am expecting the entire libraries in git hub will be available in my local system.
But I am seeing only the main file in lib folder . Where the other dependend files will be placed.
npm install --save-dev jasmine-ajax
Executed the above command and I am not seeing all the files under source in my local view.
https://github.com/jasmine/jasmine-ajax
Thanks
When you install a module like you did, it is placed in node_modules folder.
Running npm install is not getting all file from github repository, but from architecture that is pushed to npm. In the jasmine-ajax github, you can see a file called .npmignore which contains src. This file works like .gitignore files, src folder is excluded when he pushed is module to npm.
File in lib folder is generated from src folder files, so it contains all you want
mock-ajax.js file, in lib folder, represents the built library. You don't need to have all files in src when you download it from npm. You can use all jasmine-ajax features in this way:
Install jasmine-ajax from NPM via npm install --save-dev jasmine-ajax;
you can then require('jasmine-ajax') inside your test-suite and access
it via the jasmine global.
When you launch a npm install without the -g flag the folder that you have to look for is node_modules in the path where you launched the command.
If you use -g flag it will be installed as a global module.
In your case the folder will be node_modules/jasmine-ajax.
The fact that the lib folder contains only the mock-ajax.js file depends on the release they made on npm registry.
The npm install command DOES NOT clone the github repository, it downloads the release from the npm registry: https://www.npmjs.com/package/jasmine-ajax
Let's say I don't want to install my local (per project) packages in node_modules - I'd like to have it under sources/node_modules instead of just node_modules. Is it possible to override it just like you can do in bower?
In bower you provide .bowerrc file with directory option, see docs. It works exactly as if you had bower_components locally - no additional files, loaders, nothing at all - just the container dir is different.
tl;dr
$ mkdir -p sources
$ ln -s package.json sources/package.json
$ npm install --prefix sources/
$ export NODE_PATH="`pwd`/sources"
Explanation
You can (as #adeneo mentioned) simply install packages to any folder with:
$ npm install --prefix sources/ my-package
This will install to sources/my-package. However, this solution is far from neat in two ways:
package.json
It sounds as though, rather than installing individual packages, what you really want to do is install everything in package.json to the sources/ folder. The problem is that when you do npm install --prefix sources/, it also looks for package.json in the sources/ folder. If that works for you, then great.
The only way I've found to keep your package.json in your project root and install node modules somewhere else is to symlink the local package.json into that directory:
$ mkdir -p sources
$ ln -s package.json sources/package.json
$ npm install --prefix sources
require
As you mentioned, you will probably want your scripts to be able to require modules like normal - require('my-module') rather than require('sources/my-module').
The NODE_PATH environment variable can help here:
$ export NODE_PATH=`pwd`/sources/node_modules
$ node -e "require('my-module')" # Success
There is an important caveat: node will look for modules in a specific order:
In a node_modules folder in the local directory
In a node_modules folder in the parent directory, then its parent etc.
In paths in the NODE_PATH, if it hasn't found the module yet
So be careful there are aren't any other node_modules folders in the current or any parent directory which mention your modules, or things could get quite confusing.
Create local_modules in your root directory and add package.json "#amazon/product-module": "file:local_modules/#amazon/product-module",
file structure
local_modules
#amazon (folder)
product-module (folder)
[add your file which overrides]
Now do npm update and you will get your local_modules/#amazon/product-module file into node_module/#amazon/product-module
This is my package.json.
If I do an npm install from the root folder, it installs all the packages. However, the ./node_modules/babel-core/ folder will only have these files:
browser.min.js
browser-polyfill.js
package.json
Some files are missing, like the register.js file.
However, if I manually install babel-core, like this: npm install babel-core, the ./node_modules/babel-core/ folder will be complete. The register.js file will not be missing.
What I don't understand is: How can some files be missing if I install all the packages but not be missing if I install a specific package?
OBS: I'm having this problem running on a Ubuntu VM. Node version: 0.12.X. This problem seems not to occur when I'm on Windows.
When I run npm install grunt I get, in my opinion, a heavily polluted project folder. In the folder node_modules there are libs like rimraf, coffescript and others I really don't want to use. Are these required for grunt itself to be able to run or are they only there for my convenience?
I would like some kind of "npm install grunt --minimal" to only install an absolute minimum of what's needed to be able to use grunt. I don't really like my project folder full of stuff that's not really my own code. I've googled the terms i can come up with, like "minimal grunt install", but only found the basic install tutorials.
Create a node_modules directory in a directory above your project's directory and do npm install grunt there. That way the modules are accessible but they aren't in your project's node_modules directory.
Another option is to use npm install -g grunt to install grunt globally.
No, you can not. Grunt is npm package and it has dependencies (this is normal). The fact is this dependencies don't pollute your project folder structure. It is normal to
add node_modules to .gitignore and don't commit it
install every npm package with --save flag (will write package to package.json) or --save-dev flag (will write package to package.json as package needed for development)
commit package.json to repository. Thus, every team member can install all packages via npm install or npm install --production
As Dan said you can install grunt globally with -g flag but this will not solve your problem as every npm package that you install will have it own dependencies (and you'll probably think that it pollutes you folder structure as well)
You know, there are a lot of things that you need for development (or production). While installing apache (or something else) you don't say that is pollutes your file system (but it has own folder and so on).
Things don't pollute file structure if they don't exist in your project repository.
use pnpm
pnpm creates the "deep" node_modules that you want
also saves disk space and network traffic : )
alternative: npm install --legacy-bundling
to produce a deep node_modules