dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.37k stars 9.99k forks source link

[release/5.0] Invalid json in package.json for the reactredux template #37520

Closed omajid closed 2 years ago

omajid commented 3 years ago

https://github.com/dotnet/aspnetcore/blob/2a46eb8736d2e8fe5b99d3ebc6d54550bea1feeb/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/ReactRedux-CSharp/ClientApp/package.json#L55-L56

The last item, lodash ..., should not end with a comma. Strictly speaking, that's not valid json. To quote https://www.json.org/json-en.html

An object is an unordered set of name/value pairs. An object begins with {left brace and ends with }right brace. Each name is followed by :colon and the name/value pairs are separated by ,comma.

npm tries to follow the spec and can't handle this.

This results in an error when trying to build this package.json:

  npm ERR! code EJSONPARSE
  npm ERR! file src/ClientApp/package.json
  npm ERR! JSON.parse Failed to parse json
  npm ERR! JSON.parse Unexpected token } in JSON at position 1514 while parsing near '\''...sh": ">=4.17.21",
  npm ERR! JSON.parse   },
  npm ERR! JSON.parse   "browserslist":...'\''
  npm ERR! JSON.parse Failed to parse package.json data.
  npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

This seems to have been introduced by https://github.com/dotnet/aspnetcore/pull/36350

mkArtakMSFT commented 3 years ago

Thanks for bringing this up. We'll already working on a fix for this.

javiercn commented 2 years ago

Fixed here https://github.com/dotnet/aspnetcore/commit/4e47fd8f759dbdeeadadf689cd4e60c614932ae3#diff-9f2c6d0b97079fb2e1b7a51298aeec41ee137410d3ab42bade78fcca7666a8a4R50