Angular &引用;npm运行构建--“生产”;Visual Studio 2017.NET Core 2.1上的错误

Angular &引用;npm运行构建--“生产”;Visual Studio 2017.NET Core 2.1上的错误,angular,visual-studio-2017,asp.net-core-2.0,publish,angular7,Angular,Visual Studio 2017,Asp.net Core 2.0,Publish,Angular7,我需要帮助,我已经用.NETCore2.1做了一个基于Angular的项目。 因此,当我尝试发布VS时,返回以下错误: 因此,错误是: 所以,我遵循了这个解决方案: 但是没有成功,我没有在我的.angular cli.json 我怎样才能解决这个问题?谢谢 日志: 0 info it worked if it ends with ok 1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe', 1 verbose cli 'C

我需要帮助,我已经用.NETCore2.1做了一个基于Angular的项目。 因此,当我尝试发布VS时,返回以下错误:

因此,错误是:

所以,我遵循了这个解决方案: 但是没有成功,我没有在我的
.angular cli.json
我怎样才能解决这个问题?谢谢

日志:

    0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build',
1 verbose cli   '--',
1 verbose cli   '--prod' ]
2 info using npm@6.4.1
3 info using node@v10.14.2
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle ApoManagement@0.0.0~prebuild: ApoManagement@0.0.0
6 info lifecycle ApoManagement@0.0.0~build: ApoManagement@0.0.0
7 verbose lifecycle ApoManagement@0.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle ApoManagement@0.0.0~build: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\projects\ApoManagement\ApoManagement\ClientApp\node_modules\.bin;C:\Program Files (x86)\Parallels\Parallels Tools\Applications;C:\Program Files\Microsoft MPI\Bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\dotnet\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Users\MYUSER\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\MYUSER\AppData\Local\Programs\Python\Python36-32\;C:\Users\MYUSER\AppData\Local\Microsoft\WindowsApps;C:\Users\MYUSER\AppData\Local\atom\bin;C:\Program Files\Microsoft VS Code\bin;C:\Users\MYUSER\AppData\Local\Microsoft\WindowsApps;"C:\Users\MYUSER\AppData\Roaming\npm;C:\Program Files\nodejs";C:\Users\MYUSER\AppData\Roaming\npm
9 verbose lifecycle ApoManagement@0.0.0~build: CWD: C:\projects\ApoManagement\ApoManagement\ClientApp
10 silly lifecycle ApoManagement@0.0.0~build: Args: [ '/d /s /c', 'ng build --extract-css "--prod"' ]
11 silly lifecycle ApoManagement@0.0.0~build: Returned: code: 1  signal: null
12 info lifecycle ApoManagement@0.0.0~build: Failed to exec build script
13 verbose stack Error: ApoManagement@0.0.0 build: `ng build --extract-css "--prod"`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:962:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid ApoManagement@0.0.0
15 verbose cwd C:\projects\ApoManagement\ApoManagement\ClientApp
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build" "--" "--prod"
18 verbose node v10.14.2
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error ApoManagement@0.0.0 build: `ng build --extract-css "--prod"`
22 error Exit status 1
23 error Failed at the ApoManagement@0.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
0信息如果它以ok结尾,它就工作了
1详细cli['C:\\Program Files\\nodejs\\node.exe',
1 verbose cli'C:\\Program Files\\nodejs\\node\u modules\\npm\\bin\\npm cli.js',
1详细cli“运行”,
1详细cli“生成”,
1详细cli'-',
1详细cli'--prod']
2信息使用npm@6.4.1
3信息使用node@v10.14.2
4详细运行脚本['prebuild'、'build'、'postbuild']
5信息生命周期ApoManagement@0.0.0~prebuild:ApoManagement@0.0.0
6信息生命周期ApoManagement@0.0.0~build:ApoManagement@0.0.0
7详细的生命周期ApoManagement@0.0.0~build:生命周期中的不安全烫发为true
8详细的生命周期ApoManagement@0.0.0~build:PATH:C:\Program Files\nodejs\node\u modules\npm\node\u modules\npm lifecycle\node gyp bin;C:\projects\ApoManagement\ApoManagement\ClientApp\node\u modules\.bin;C:\ProgramFiles(x86)\Parallels\Parallels工具\应用程序;C:\Program Files\Microsoft MPI\Bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\ProgramFiles\dotnet\;C:\ProgramFiles(x86)\Skype\Phone\;C:\ProgramFiles(x86)\Microsoft SQL Server\130\DTS\Binn\;C:\ProgramFiles(x86)\Microsoft SQL Server\140\DTS\Binn\;C:\ProgramFiles(x86)\Microsoft SQL Server\110\DTS\Binn\;C:\ProgramFiles(x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\ProgramFiles(x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\ProgramFiles(x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\ProgramFiles(x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\ProgramFiles(x86)\Microsoft SQL Server\140\Tools\Binn\;C:\ProgramFiles(x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Microsoft VS Code\bin;C:\ProgramFiles\Git\cmd;C:\ProgramFiles\nodejs\;C:\Users\MYUSER\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\MYUSER\AppData\Local\Programs\Python\Python36-32\;C:\Users\MYUSER\AppData\Local\Microsoft\WindowsApps;C:\Users\MYUSER\AppData\Local\atom\bin;C:\Program Files\Microsoft VS Code\bin;C:\Users\MYUSER\AppData\Local\Microsoft\WindowsApps;“C:\Users\MYUSER\AppData\Roaming\npm;C:\Program Files\nodejs”;C:\Users\MYUSER\AppData\Roaming\npm
9详细的生命周期ApoManagement@0.0.0~build:CWD:C:\projects\ApoManagement\ApoManagement\ClientApp
10愚蠢的生命周期ApoManagement@0.0.0~build:Args:['/d/s/c','ng build--extract css--prod']
11愚蠢的生命周期ApoManagement@0.0.0~build:返回:代码:1信号:null
12信息生命周期ApoManagement@0.0.0~build:无法执行生成脚本
13详细堆栈错误:ApoManagement@0.0.0build:`ng build--extract css--prod“`
13详细堆栈退出状态1
13 EventEmitter上的详细堆栈。(C:\Program Files\nodejs\node\u modules\npm\node\u modules\npm lifecycle\index.js:301:16)
13 EventEmitter.emit上的详细堆栈(events.js:182:13)
13子进程上的详细堆栈。(C:\Program Files\nodejs\node\U modules\npm\node\U modules\npm lifecycle\lib\spawn.js:55:14)
13 ChildProcess.emit上的详细堆栈(events.js:182:13)
13 maybeClose的详细堆栈(internal/child_process.js:962:16)
13 Process.ChildProcess.\u handle.onexit处的详细堆栈(internal/child\u Process.js:251:5)
14详细的pkgidApoManagement@0.0.0
15详细cwd C:\projects\ApoManagement\ApoManagement\ClientApp
16详细窗口\u NT 10.0.17134
17详细的argv“C:\\Program Files\\nodejs\\node.exe”C:\\Program Files\\nodejs\\node\U模块\\npm\\bin\\npm cli.js”“运行”“生成”“--prod”
18详细节点v10.14.2
19详细的npm v6.4.1
20错误代码ELIFECYCLE
21错误1
22错误ApoManagement@0.0.0build:`ng build--extract css--prod“`
22错误退出状态1
23发生错误时失败ApoManagement@0.0.0构建脚本。
23错误这可能不是npm的问题。上面可能还有其他日志输出。
24详细退出[1,true]

我和你有同样的问题,我通过以下方法解决了这个问题:

编辑.csproj文件:
右键单击项目
-选择
编辑.csproj

替换此项:

<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />

为此:

<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build --prod" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />


基本上,命令
npm run build--prod
,应该是
npm run build--prod

日志中有什么?我还可以问一下,为什么创建一个.net core angular网站,而您可以轻松创建一个基于angular的网站cli@JackM我需要服务器api,我选择.net。我已经用谁/什么启动了命令npm run build?Personnaly更新了答案,我不理解这个错误,但是要尝试的一件事是更新节点和npm。私下说一句,您仍然可以将您的api用于使用angular cli开发的网站(我认为这是推荐的),您似乎可以通过
ng build--extract css--prod”-
重现此错误,但实际上这是错误的,您可以使用npm运行build--prod,如果这给您带来了一个错误,那是因为您在aot中的typescript构建有问题。实际上,你可以转到angular应用程序,运行npm run build--prod,检查详细错误,修复错误,然后返回发布。如果我遇到这个问题,请使用angular 9+ASP.NET Core 3.1。Angular CLI项目可以很好地构建生产环境,build:ssr命令也可以很好地工作。然而,当我启用