angular-cli: Cannot change the 'read' location for chunks

Please provide us with the following information:


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


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.30 node: 7.5.0 os: win32 x64 @angular/common: 2.4.6 @angular/compiler: 2.4.6 @angular/core: 2.4.6 @angular/forms: 2.4.6 @angular/http: 2.4.6 @angular/platform-browser: 2.4.6 @angular/platform-browser-dynamic: 2.4.6 @angular/router: 3.4.6 @angular/upgrade: 2.4.6 @angular/cli: 1.0.0-beta.30 @angular/compiler-cli: 2.4.6

Repro steps.

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

I have a couple of lazy routes and everything is compiled and generated in “webapproot/ng/dist/” The problem is that even though in my index.html I’m referencing the scripts like this

<script src="/ng/dist/inline.bundle.js"></script> <script src="/ng/dist/polyfills.bundle.js"></script> <script src="/ng/dist/styles.bundle.js"></script> <script src="/ng/dist/vendor.bundle.js"></script> <script src="/ng/dist/main.bundle.js"></script>

the lazy routes chunks always try to load from ‘/0.chunk.js’ instead of ‘/ng/dist/0.chunk.js’

Is there any way to instruct the cli/angular to read the chunks for the proper folder?

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.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 14
  • Comments: 23

Most upvoted comments

I managed to make it work by adding “deployUrl” : “/ng/dist/”, in apps in .angular-cli.json

I would also love to see an option to change where the chunk files are served from.

My app folder structure looks like this:

- css
--- styles.css
- js
--- bundle.js
--- 0.chunk.js
--- 1.chunk.js

My lazy loaded paths cannot be loaded because the chunks are trying to be loaded from localhost:3000/0.chunk.js instead of localhost:3000/js/0.chunk.js. To make it work, I have to build all the js files into the root folder.


By the way, you can work directly to webpack.config.js by ejecting it.

Use ng eject.


@cristianbressan I’m trying to load my chunks from a CDN. However adding “publicPath” did not fix the issue as the chunks are not getting loaded from the CDN. Any ideas on how to fix this?

I do not think this should be closed, the lazy routes should ideally be taking into account the base href

i’m having a very similar issue… the “deployUrl” allows me to find the js chunk files… However, now the chunked file’s cannot use absolute paths?

in my css, I use /images everywhere, but the chunked files are looking for /images inside of the dist folder.

Any ideas!?!?!

Hi Mila,

I’m using Asp.Net Mvc so what I did was:

  1. I left angular making calls for the lazy module files to /0.chunk.js or 0.guid.chunk.js
  2. I added in the routing of my MVC app a custom route with a regex exp that caches these requests and redirects them to a controller
  3. In the controller I’m appending to the requested path /ng/dist and return the file from the new path Hope this helps Best regards, Anatolie Darii

From: Mila Sent: Tuesday, May 16, 2017 11:59 PM To: angular/ Cc: Anatolie; Subject: Re: [angular/angular-cli] Cannot change the ‘read’ location for chunks (#4531)

@anatolie-darii Would you mind elaborating on your solution (custom route to serve the chunks)? I am having trouble with this myself right now.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread

I ended up making a custom route in my mvc app to serve the chunks. But for your CDN you could use IIS rewrite or something similar I suppose. Still would be nice if this could be configured. Love the latest RC btw, especially the fact that you can build multiple apps

One issue that I’ve run into trying to implement this with the current --base-href solution is that I would like my application to be served from my CDN, which is on a different domain from the current page. But it appears there are security restrictions on setting base href to a different domain. I haven’t been able to find a workaround for this yet.