Skip to content

Error in ng build --prod that doesn't happen with ng serve --prod #14747

Closed
@hugodes

Description

@hugodes

🐞 Bug report

Command (mark with an x)

- [ ] new
- [x] build
- [x] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

This problem didn't happen with angular/cli 7.x

Description

When I serve the app via ng serve --prod the app runs fine.

When I serve the files outputted by with a server (apache, nginx) ng build --prod the app fails to load with js error.

🔬 Minimal Reproduction

Here is a bear-bones repo that exposes the bug: https://github.com/hugodes/cli-2015

🔥 Exception or Error

The problem here is that this errors appears with ng build --prod but not with ng serve --prod


main-es2015.4cf9183c1dd8f352bda7.js:1 Uncaught ReferenceError: process is not defined
    at Object.md97 (main-es2015.4cf9183c1dd8f352bda7.js:1)
    at f (runtime-es2015.858f8dd898b75fe86926.js:1)
    at Object.Sp1i (main-es2015.4cf9183c1dd8f352bda7.js:1)
    at f (runtime-es2015.858f8dd898b75fe86926.js:1)
    at Module.zUnb (main-es2015.4cf9183c1dd8f352bda7.js:1)
    at f (runtime-es2015.858f8dd898b75fe86926.js:1)
    at Object.1 (main-es2015.4cf9183c1dd8f352bda7.js:1)
    at f (runtime-es2015.858f8dd898b75fe86926.js:1)
    at t (runtime-es2015.858f8dd898b75fe86926.js:1)
    at Array.r [as push] (runtime-es2015.858f8dd898b75fe86926.js:1)

🌍 Your Environment




Angular CLI: 8.0.2
Node: 10.16.0
OS: darwin x64
Angular: 8.0.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.2
@angular-devkit/build-angular     0.800.2
@angular-devkit/build-optimizer   0.800.2
@angular-devkit/build-webpack     0.800.2
@angular-devkit/core              8.0.2
@angular-devkit/schematics        8.0.2
@angular/cli                      8.0.2
@ngtools/webpack                  8.0.2
@schematics/angular               8.0.2
@schematics/update                0.800.2
rxjs                              6.5.2
typescript                        3.4.5
webpack                           4.30.0

Anything else relevant?
The error comes from the fact that the aws-sdk is dependent on node specific variables that are not present in a browser context.

But the problem is that the error should both happen with ng serve and ng build.
Why ? Multiple reasons:

  1. Developers use ng serve for development and they should be made aware errors that will end up on production.
  2. Also it will be easier for reporting the "process shim" bug to the aws team, if they just have to run ng serve instead of having to setup a third party web server.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions