npm init,'npm ERR!名称字段必须是字符串。

时间:2016-04-05 08:31:15

标签: npm npm-init

每当我尝试运行npm init,并且只接受默认值时,在基本项目中,我会收到此错误:

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

我在OSX上运行。这是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 ]

3 个答案:

答案 0 :(得分:2)

我相信您创建的节点项目的“名称”格式为“MyProject”(package.son中的名称字段)。它应该是小案例,如“myproject”或“my-project”。 请参考 https://docs.npmjs.com/files/package.json

答案 1 :(得分:0)

在新的 Laravel 5.3 项目上执行Took 0.555 seconds to read 3.146 MB of data 时遇到了同样模糊的错误(尝试关注this tutorial)。

查看npm install vue vue-router --save文件(感谢@PramodTK提示),package.json属性丢失了。所以我补充道:

name

{ "name": "my-project-name", ... 文件的开头,然后我的package.json命令正常工作。

答案 2 :(得分:0)

我有这个:

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

在我的 package.json 文件中。所以你需要删除这样的符号 [],如果你的 package.json 文件中有这样的符号才能安装包。