简体   繁体   English

无法解析package.json

[英]Unable to parse package.json

i'm trying to upload a javascript nodejs project to Heroku. 我正在尝试将javascript nodejs项目上载到Heroku。 Localhost works perfectly but when i try to upload it gives me a unable to parse error at : Localhost可以完美运行,但是当我尝试上传时,它无法解析以下错误:

...
"engines" : { "node" : ">0.11.9" },
...

The Error Message : Invalid numeric literal at line 12, column 0 错误消息:无效的数字文字在第12行,第0列

Full JSON File: 完整的JSON文件:

{
  "name": "browsergameprojecz",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "dependencies": {
    "express": "^4.16.3",
    "mongojs": "^2.6.0",
    "socket.io": "^2.1.1"
  },
  "engines" : { "node" : ">0.11.9" },

  "devDependencies": {},
  "scripts": {
    "start": "node app.js"
  },
  "author": "",
  "license": "ISC"
}

在此处输入图片说明

This is from the official npm docs. 这是来自官方的npm文档。 It looks like you need a range for a version not just a lower limit. 看起来您需要一个版本范围,而不仅仅是一个下限。 Or an approximate version. 或近似版本。 However from my experience with Heroku I have never needed this it seems heroku will probably use a node version much higher. 但是根据我在Heroku上的经验,我从不需要它,似乎heroku可能会使用更高版本的节点。 Also if you need a specific version there is such a thing called engineStrict which you can have a look at in the official npm docs. 另外,如果您需要特定的版本,则有一个名为engineStrict的东西,您可以在官方的npm文档中查看。

there are Linters for that, eg. 有林特,例如。 the Package JSON Validator 包JSON验证程序

... which lets one inspect the validity of such JSON files. ...,让您检查此类JSON文件的有效性。

besides Node 0.11.9 is roughly 5 years old and tagged as unstable 除了Node 0.11.9大约有5年的历史并且被标记为unstable

... consider upgrading, while this is possible in combination with the rest. ...考虑升级,但可以与其他结合使用。

there might be Windows line-ending in that file ...as it often is the case, when "everything looks fine", but still not works are excepted. 该文件中可能有Windows行尾...通常情况下,“一切都很好”但仍然无法正常工作时,除外。 dos2unix can be used to fix them. dos2unix可用于修复它们。

https://techblog.dorogin.com/writing-cross-platform-npm-scripts-on-windows-79c510339ea6 hints for, that when files have a UTF-8 BOM 0x EF BB BF at the beginning, this also makes it un-parse-able. https://techblog.dorogin.com/writing-cross-platform-npm-scripts-on-windows-79c510339ea6提示,当文件开始时具有UTF-8 BOM 0x EF BB BF时,这也使其不起作用-parse-能。 unless checking this with a hex-editor, one can not know. 除非使用十六进制编辑器进行检查,否则不知道。 simply creating a new package.json with UTF-8 endoding and UNIX \\n line-endings should resolve the issue. 只需使用UTF-8结尾和UNIX \\n行尾创建一个新的package.json即可解决此问题。

When the data is upload to the client from the server side in JSON format, some special characters can not be displayed directly when the JS is displayed on the HTML page. 当数据以JSON格式从服务器端上传到客户端时,如果在HTML页面上显示JS,则某些特殊字符将无法直接显示。 As the background is passed through the <b>msg</b> , it is displayed in the HTML page msg by JS, and it is not msg . 当背景通过<b>msg</b>传递时,它由JS显示在HTML页面msg ,而不是msg This is due to the content between < and > as HTML. 这是由于<>之间的内容为HTML。 Tagging, and start with HTML as entity, so the display is not normal. 进行标记,并以HTML作为实体开始,因此显示不正常。 The solution is simple, and can be rendered before JS is rendered to HTML pages. 该解决方案很简单,可以在将JS呈现到HTML页面之前呈现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM