4

I need an help, i've made a project on Angular based with .Net Core 2.1. So when i try to publish VS return me this error:

enter image description here

So the error is: enter image description here

enter image description here

So, i've followed this solution: The command "npm run build -- --prod" exited with code 1 error but without succes, i didn't found this: npm run build -- --prod on my .angular-cli.json How can i solve this problem ? Thanks

enter image description here

The logs:

    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 ]
Mr. Developer
  • 3,295
  • 7
  • 43
  • 110

1 Answers1

10

I had the same problem as you, I've managed to solve it by:

Edit your .csproj file: Right click on you project - select Edit ____.csproj

Replace this:

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

With this:

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

Basically the command npm run build -- --prod, should be npm run build --prod

O. Shai
  • 703
  • 7
  • 22
  • 1
    That's actually wrong, you can use npm run build -- --prod and if this is giving you an error it's because you have something wrong with your typescript building in aot. You can actually go to your angular app, and run npm run build -- --prod and check the detailed errors, fix them and go back to publish it – Shakawkaw Mar 01 '20 at 12:25
  • I'm having this problem, using Angular 9 + ASP.NET Core 3.1. The Angular CLI project builds fine for production and the build:ssr command works fine too. However When I enable the BuildServerSideRenderer project setting, VS2019 gets an error when building the SSR version. any ideas? – Nexus Apr 14 '20 at 13:27
  • 2
    @Nexus I can confirm removing the -- on both lines fixed the dotnet publish command for me using Angular 9 + ASP.NET Core 3.1. Do you know how to publish this as I am having difficulty getting this up and running on IIS with iisnode? – tfa Apr 25 '20 at 05:16
  • 1
    @tfa yup removing the redundant double dash fixes the build issue. I'm still trying to figure out how to deploy Angular SSR with .NET Core on IIS. NodeServices are deprecated in .NET Core 3.x so the old options (UseSpaPrerendering) are of no use. I haven't found anything useful yet, contacted a few developers and websites, still no luck. The ASP.NET Core docs and Angular Universal docs need much more up-to-date content. Sorry I couldn't be helpful at this stage. – Nexus Apr 25 '20 at 21:06
  • I got it working today and wrote the instructions here comment if you have any questions https://stackoverflow.com/questions/60187707/angular-9-0-ssr-is-compiled-but-i-cannot-publish-it-on-the-server?noredirect=1#comment108657363_60187707 – tfa Apr 25 '20 at 21:08