ng build - getting 404 for all static assets

563 Views Asked by At

I generated an Angular 7 app using @angular/cli, I haven't changed anything, all default settings - I just created it 20 minutes ago.

When I run ng build or ng build --prod, it puts the build in:

dist/
  appname/

in my case that's

dist/
  api-app/

looks like this:

enter image description here

The weird thing is that when I load index.html, I get 404s for all the static assets:

<-- [GET] /
--> 200 OK / (dist/api-app/index.html) 592 Byte (19.188ms)
<-- [GET] /styles.3ff695c00d717f2d2a11.css
<-- [GET] /runtime.ec2944dd8b20ec099bf3.js
--> 404 /styles.3ff695c00d717f2d2a11.css (2.416ms)
--> 404 /runtime.ec2944dd8b20ec099bf3.js (2.236ms)
<-- [GET] /polyfills.20ab2d163684112c2aba.js
<-- [GET] /main.9113cc683ed9b1c834cf.js
--> 404 /polyfills.20ab2d163684112c2aba.js (0.471ms)
--> 404 /main.9113cc683ed9b1c834cf.js (0.550ms)
<-- [GET] /styles.3ff695c00d717f2d2a11.css
--> 404 /styles.3ff695c00d717f2d2a11.css (0.732ms)

I tried loading the index.html page using several different servers, and it always gets 404s for the static assets. Does anyone know why? Here is the index.html file:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>ApiApp</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="stylesheet" href="styles.3ff695c00d717f2d2a11.css">
</head>
<body>
<app-root></app-root>
<script type="text/javascript" src="runtime.ec2944dd8b20ec099bf3.js"></script>
<script type="text/javascript" src="polyfills.20ab2d163684112c2aba.js"></script>
<script type="text/javascript" src="main.9113cc683ed9b1c834cf.js"></script>
</body>
</html>
1

There are 1 best solutions below

0
On

The reason was because the web server I was running had the wrong root. I did this:

$ npm i -g static-server
$ cd dist/api-app
$ static-server

now it works