3

Whenever I try and run npm init, and just accept the default values, in a basic project, I get this error:

npm ERR! Darwin 15.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "init"
npm ERR! node v5.0.0
npm ERR! npm  v3.3.6

npm ERR! name field must be a string.
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/taylorhuston/Code/projects/Site_49thFloor/npm-debug.log

I am running on OSX. Here is the entire contents of the npm-debug.log

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'init' ]
2 info using npm@3.3.6
3 info using node@v5.0.0
4 verbose config Skipping project config: /Users/taylorhuston/.npmrc. (matches userconfig)
5 silly package data undefined
6 info init written successfully
7 verbose stack Error: name field must be a string.
7 verbose stack     at Object.module.exports.fixNameField (/usr/local/lib/node_modules/npm/node_modules/normalize-package-data/lib/fixer.js:206:13)
7 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/normalize-package-data/lib/normalize.js:32:38
7 verbose stack     at Array.forEach (native)
7 verbose stack     at normalize (/usr/local/lib/node_modules/npm/node_modules/normalize-package-data/lib/normalize.js:31:15)
7 verbose stack     at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:338:5)
7 verbose stack     at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:113:5)
7 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:300:12
7 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:76:16
7 verbose stack     at tryToString (fs.js:414:3)
7 verbose stack     at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:401:12)
8 verbose cwd /Users/taylorhuston/Code/projects/Site_49thFloor
9 error Darwin 15.4.0
10 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "init"
11 error node v5.0.0
12 error npm  v3.3.6
13 error name field must be a string.
14 error If you need help, you may report this error at:
14 error     <https://github.com/npm/npm/issues>
15 verbose exit [ 1, true ]
Taylor Huston
  • 1,104
  • 3
  • 15
  • 31

3 Answers3

2

I believe the "name" of the node project you created is in the format "MyProject"(name field in package.son). It should be in small case like "myproject" or "my-project". Please refer https://docs.npmjs.com/files/package.json

PramodTK
  • 66
  • 3
1

Got the same obscure error doing an npm install vue vue-router --save on a fresh Laravel 5.3 project (trying to follow this tutorial).

Looking at the package.json file (thanks @PramodTK for the hint), the name property was simply missing. So I've added:

{
  "name": "my-project-name",
  ...

at the beginning of the package.json file, then my npm install command worked properly.

Maxime Pacary
  • 22,336
  • 11
  • 85
  • 113
0

I had this:

"lint-staged":{"src/**/*.{js,jsx,json,css}": ["prettier --single-quote --write","git add"]}

in my package.json file. So you need to remove such symbols [], if you have in your package.json file to be able to install packages.

Ali Safari
  • 1,535
  • 10
  • 19