npm启动错误,但节点index.js的作品
我开始学习nodejs,并按照本教程创build一个简单的Web应用程序。
https://blog.risingstack.com/node-hero-tutorial-getting-started-with-node-js/
根据教程,我可以使用'npm start'或node index.js'来运行web应用程序。 当我使用节点install.js它工作,并给出结果。 但是,当我使用npm开始发生此错误。
npm ERR! Linux 4.4.0-38-generic npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start" npm ERR! node v4.2.6 npm ERR! npm v3.5.2 npm ERR! file /var/www/html/nodejs/package.json npm ERR! code EJSONPARSE npm ERR! Failed to parse json npm ERR! Unexpected token '/' at 1:1 npm ERR! // package.json npm ERR! ^ npm ERR! File: /var/www/html/nodejs/package.json npm ERR! Failed to parse package.json data. npm ERR! package.json must be actual JSON, not just JavaScript. npm ERR! npm ERR! This is not a bug in npm. npm ERR! Tell the package author to fix their package.json file. JSON.parse npm ERR! Please include the following file with any support request: npm ERR! /var/www/html/nodejs/npm-debug.log
由于我是nodejs和npm的初学者,我不知道哪里出了问题。 有谁知道如何解决这一问题 ? 提前致谢。
你的package.json有错误。 你不能使用注释// package.json
。 有关更多信息,请参阅此答案 。
要描述你遇到的两种情况:
当您使用npm start
,您使用npm的CLI查找该项目目录的package.json并运行存在于起始值的任何命令。 如果你想使用npm start
来运行你的应用npm start
,你可以在package.json
有一行:
... "scripts": { "start": "node index.js" }, ...
package.json
是JSON所以它需要像有效的JSONparsing。
当你使用node index.js
,你完全绕过了npm,并使用节点来激发index.js。 如果在package.json
有一个parsing错误,那没关系,因为这个文件没有被使用。