代码之家  ›  专栏  ›  技术社区  ›  Mr. Developer

Visual Studio 2017.NET Core 2.1 Angular上的“npm run build--prod”错误

  •  1
  • Mr. Developer  · 技术社区  · 6 年前

    我需要帮助,我做了一个基于.NET Core2.1的Angular项目。 所以当我尝试发布vs返回这个错误时:

    enter image description here

    所以错误是: enter image description here

    enter image description here

    所以,我遵循了这个解决方案: The command "npm run build -- --prod" exited with code 1 error 但是没有成功,我没有找到这个: NPM运行生成---prod 关于我的 .angular-cli.json 我怎样才能解决这个问题?谢谢

    enter image description here

    日志:

        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 ]
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   O. Shai    6 年前

    我和你有同样的问题,我设法解决了:

    编辑.csproj文件: Right click on you project -选择 Edit ____.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