question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Confused about actual webroot with "ng serve", *.bundle.js not loading

See original GitHub issue

Please provide us with the following information:

OS?

Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?) W10

Versions.

Please run ng --version. If there’s nothing outputted, please run in a Terminal: node --version and paste the result here: angular-cli: 1.0.0-beta.25.5 node: 6.9.1 os: win32 x64 @angular/common: 2.4.3 @angular/compiler: 2.4.3 @angular/core: 2.4.3 @angular/forms: 2.4.3 @angular/http: 2.4.3 @angular/platform-browser: 2.4.3 @angular/platform-browser-dynamic: 2.4.3 @angular/router: 3.4.3 @angular/compiler-cli: 2.4.3

Repro steps.

Was this an app that wasn’t created using the CLI? What change did you do on your code? etc.

Hi,

I got stuck and I hope you could help me out.

I started out normally with the CLI and then decided to put the app behind a proxy. The proxy must distribute requests to various services, all under a common origin. For that, I needed to add a web root prefix to the app, which ran under 4200/ as per default. The app should run under 4200/monitoring/ui so that the proxy can route everything under 80/monitoring/ui to 4200/monitoring/ui

I did the following:

index.html: changed base href from “/” to “/monitoring/ui/”

.angular-cli.json: “outDir”: “dist/monitoring/ui”

The build worked ok. Now, with ng serve running, http://localhost:4200/monitoring/ui will open, but all the .bundle.js files get a 404. I noticed that it is totally irrelevant what I type behind 4200, index.html will always open.

With an external http server sitting on ./dist instead of ng serve the app starts fine, but the angular router won’t work anymore.

I don’t understand where ng serve actually has its web root and how this is intertwined with the angular router.

Thanks!

The log given by the failure.

Normally this include a stack trace and some more information.

Mention any other details that might be useful.


Thanks! We’ll be in touch soon.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
Meligycommented, Jan 26, 2017

I got it working!

One thing I thought you might try to get ng serve to work, is adding a proxy config as explained in README.

I created a JSON file proxy.conf.json that looks like

{
  "/monitoring/ui/**": {
    "target": "http://localhost:4200/",
    "pathRewrite": {
      "^/monitoring/ui": ""
    }
  }
}

(The config is inspired by examples from Webpack docs linked in the Angular CLI proxy section)

And ensured the base href is set correctly in my src/index.html like:

<base href="/monitoring/ui/">

Then ran ng serve like this:

ng serve --proxy=proxy.conf.json

It worked just fine including routing, even lazy loading.

One thing to beware of though is that ng serve is meant for development and debugging. It’s NOT meant to run as a production server.

For production you need to bring your own server and use it with dist folder. In that context, the previous comment should help you.

1reaction
Meligycommented, Jan 26, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

angular throws 404 for *.bundle.js files when using a custom ...
The symptom occurs under the described circumstances, because the files are served on a root level by angular cli, no matter what the...
Read more >
angular/angular-cli - Gitter
Using the ng serve it works. I got my page as it should be. My routes are: const routes: Routes = [ {...
Read more >
Integrating the Angular 4 CLI With Visual Studio Professional ...
Load all the JavaScript bundles generated by the Angular CLI ng build command; Support three modes, debug mode, Web API only mode and...
Read more >
30 Answers from Stack Overflow to the most popular webpack ...
Those tools like Webpack and Browserify solve these problems by translating such ... start.js creates both client and server side bundles, ...
Read more >
Untitled
Anthony cincotta esq, Fabrik in china explodiert, Las 3 js instrumental, ... Royal hand vac, Mathematical analysis of physical problems wallace pdf, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found