1

When I run this:

npm install angular-mocks --save-dev

I get angular-mocks in ./node_modules and a reference to angular mocks in ./package.json

When I run this:

npm install angular-mocks --prefix ./Content/libs

I get angular-mocks in ./Content/libs/node_modules

When I run this:

npm install angular-mocks --save-dev --prefix ./Content/libs

I get angular-mocks in ./Content/libs/nod_modules but no reference to anguar-mocks in ./package.json

Why is npm not saving the reference in package.json when I use --prefix?

pQuestions123
  • 4,471
  • 6
  • 28
  • 59

1 Answers1

2

Why is npm not saving the reference in package.json when I use --prefix?

It is (or at least will do), but it is expecting package.json to be in the parent folder of wherever it drops the node_modules folder.

In your case this would be ./Content/libs.

Try it out:

mkdir -p ~/test/Content/libs
cd ~/test/Content/libs
npm init (accept defaults)
cd ~/test
npm install angular-mocks --save-dev --prefix ./Content/libs
cat ~/test/Content/libs/package.json

package.json:

{
  "name": "libs",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "angular-mocks": "^1.4.8"
  }
}

As you can see, angular-mocks has been saved to the devDependencies.

This SO thread contains a little more detail on installing local packages to a custom location: npm local install package to custom location

Community
  • 1
  • 1
James Hibbard
  • 16,490
  • 14
  • 62
  • 74