0

我在 mac OS 12.0.1 上创建一个带有 asp.net 核心的 React.js 应用程序,我试图在初始设置后构建和运行这个应用程序:

在此处输入图像描述

但后来我得到这个错误:

/Users/user/Projects/NameProject/NameProject/NameProject.csproj(5,5):Error MSB3073: The command "npm install" exited with code 1. (MSB3073)

这是我的日志:

Building ReactReduxNetTest (Debug)
Build started 11/18/2021 10:56:27 AM.
__________________________________________________
Project "/Users/user/Projects/ReactReduxNetTest/ReactReduxNetTest/ReactReduxNetTest.csproj" (Build target(s)):

Target GenerateTargetFrameworkMonikerAttribute:
  Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
Target CoreGenerateAssemblyInfo:
  Skipping target "CoreGenerateAssemblyInfo" because all output files are up-to-date with respect to the input files.
Target _DiscoverMvcApplicationParts:
  Skipping target "_DiscoverMvcApplicationParts" because all output files are up-to-date with respect to the input files.
Target _CoreGenerateRazorAssemblyInfo:
  Skipping target "_CoreGenerateRazorAssemblyInfo" because all output files are up-to-date with respect to the input files.
Target CoreCompile:
  Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
Target GenerateStaticWebAssetsManifest:
  Skipping target "GenerateStaticWebAssetsManifest" because all output files are up-to-date with respect to the input files.
Target _GenerateScopedCssFiles:
  Skipping target "_GenerateScopedCssFiles" because it has no outputs.
Target ResolveTagHelperRazorGenerateInputs:
  Skipping target "ResolveTagHelperRazorGenerateInputs" because all output files are up-to-date with respect to the input files.
Target RazorCoreGenerate:
  Skipping target "RazorCoreGenerate" because all output files are up-to-date with respect to the input files.
Target CoreGenerateRazorTargetAssemblyInfo:
  Skipping target "CoreGenerateRazorTargetAssemblyInfo" because all output files are up-to-date with respect to the input files.
Target RazorCoreCompile:
  Skipping target "RazorCoreCompile" because all output files are up-to-date with respect to the input files.
Target _CopyFilesMarkedCopyLocal:
    Touching "/Users/user/Projects/ReactReduxNetTest/ReactReduxNetTest/obj/Debug/net5.0/ReactReduxNetTest.csproj.CopyComplete".
Target _CopyOutOfDateSourceItemsToOutputDirectory:
  Skipping target "_CopyOutOfDateSourceItemsToOutputDirectory" because all output files are up-to-date with respect to the input files.
Target GenerateBuildDependencyFile:
  Skipping target "GenerateBuildDependencyFile" because all output files are up-to-date with respect to the input files.
Target GenerateBuildRuntimeConfigurationFiles:
  Skipping target "GenerateBuildRuntimeConfigurationFiles" because all output files are up-to-date with respect to the input files.
Target CopyFilesToOutputDirectory:
    ReactReduxNetTest -> /Users/user/Projects/ReactReduxNetTest/ReactReduxNetTest/bin/Debug/net5.0/ReactReduxNetTest.dll
Target _RazorCopyFilesToOutputDirectory:
    ReactReduxNetTest -> /Users/user/Projects/ReactReduxNetTest/ReactReduxNetTest/bin/Debug/net5.0/ReactReduxNetTest.Views.dll
    Touching "/Users/user/Projects/ReactReduxNetTest/ReactReduxNetTest/obj/Debug/net5.0/ReactReduxNetTest.csproj.CopyComplete".
Target DebugEnsureNodeEnv:
    node --version
    v12.16.1
    Restoring dependencies using 'npm'. This may take several minutes...
    npm install
    npm ERR! code EJSONPARSE
    npm ERR! file /Users/user/Projects/ReactReduxNetTest/ReactReduxNetTest/ClientApp/package.json
    npm ERR! JSON.parse Failed to parse json
    npm ERR! JSON.parse Unexpected token } in JSON at position 1528 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.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /Users/user/.npm/_logs/2021-11-18T14_56_28_644Z-debug.log
    /Users/user/Projects/ReactReduxNetTest/ReactReduxNetTest/ReactReduxNetTest.csproj(30,5): error MSB3073: The command "npm install" exited with code 1.
Done building target "DebugEnsureNodeEnv" in project "ReactReduxNetTest.csproj" -- FAILED.

Done building project "ReactReduxNetTest.csproj" -- FAILED.

Build FAILED.

/Users/user/Projects/ReactReduxNetTest/ReactReduxNetTest/ReactReduxNetTest.csproj(30,5): error MSB3073: The command "npm install" exited with code 1.
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.03

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Build: 1 error, 0 warnings

4

1 回答 1

3

此错误日志指出发生了什么:

    npm install
    npm ERR! code EJSONPARSE
    npm ERR! file /Users/user/Projects/ReactReduxNetTest/ReactReduxNetTest/ClientApp/package.json
    npm ERR! JSON.parse Failed to parse json
    npm ERR! JSON.parse Unexpected token } in JSON at position 1528 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.

npm正在尝试解析/Users/user/Projects/ReactReduxNetTest/ReactReduxNetTest/ClientApp/package.json但无法解析,因为它在package.json文件中发现了意外字符。

这实际上是具有格式错误package.json文件的 .NET 模板中的一个错误:https ://github.com/dotnet/aspnetcore/issues/37520

要修复它,请删除">=4.17.21",以下行中多余的逗号package.json

   "lodash": ">=4.17.21", 
 },

它应该如下所示:

   "lodash": ">=4.17.21"
 },

这与Microsoft 在此处的 .NET 模板中所做的修复相同。

于 2021-11-18T15:30:29.380 回答