npm not installing from package.json file on windo

2019-09-10 10:10发布

问题:

I tried installing a bunch of files from package.json file underneath a directory called "contacts". However, I get the following error:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\nodejs\\\\node.exe',
1 verbose cli   'C:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'install',
1 verbose cli   '-d' ]
2 info using npm@1.3.2
3 info using node@v0.10.13
4 verbose node symlink C:\nodejs\\node.exe
5 error install Couldn't read dependencies
6 error Error: Invalid name: "angular-$resource-example"
6 error     at ensureValidName (C:\nodejs\node_modules\npm\node_modules\read-package-json\node_modules\normalize-package-data\lib\fixer.js:281:15)
6 error     at Object.module.exports.fixNameField (C:\nodejs\node_modules\npm\node_modules\read-package-json\node_modules\normalize-package-data\lib\fixer.js:196:5)
6 error     at C:\nodejs\node_modules\npm\node_modules\read-package-json\node_modules\normalize-package-data\lib\normalize.js:29:38
6 error     at Array.forEach (native)
6 error     at normalize (C:\nodejs\node_modules\npm\node_modules\read-package-json\node_modules\normalize-package-data\lib\normalize.js:28:15)
6 error     at final (C:\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:310:33)
6 error     at then (C:\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:124:33)
6 error     at C:\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:234:40
6 error     at fs.js:266:14
6 error     at Object.oncomplete (fs.js:107:15)
7 error If you need help, you may report this log at:
7 error     <http://github.com/isaacs/npm/issues>
7 error or email it to:
7 error     <npm-@googlegroups.com>
8 error System Windows_NT 6.2.9200
9 error command "C:\\nodejs\\\\node.exe" "C:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-d"
10 error cwd C:\Users\Nafiul Islam\Desktop\Contacts
11 error node -v v0.10.13
12 error npm -v 1.3.2
13 verbose exit [ 1, true ]

The following is the package.json file:

{
  "name": "angular-$resource-example",
  "version": "0.0.1",
  "description": "Easier Javascript Apps with AngularJS",
  "main": "server/server.js",
  "author": "Tom Ashworth",
  "license": "MIT",
  "dependencies": {
    "express": "~3.0.6",
    "mongoose": "~3.5.4"
  }
}

回答1:

it looks like the name of your package is invalid. see https://docs.npmjs.com/files/package.json



回答2:

Your "name" is passed by the following code:

function ensureValidName (name, strict) {
  if (name.charAt(0) === "." ||
      name.match(/[\/@\s\+%:]/) ||
      name !== encodeURIComponent(name) ||
      (strict && name !== name.toLowerCase()) ||
      name.toLowerCase() === "node_modules" ||
      name.toLowerCase() === "favicon.ico") {
        throw new Error("Invalid name: " + JSON.stringify(name))
  }
}

It can't start with a "." and it must not have any special characters so in your case I think the $ i throwing the error.

The general rule is to stick to words separated with hyphens or underscores and do not include any variables.



标签: npm