George Edwards
George Edwards

Reputation: 9229

Static assets not serving on Heroku but do locally?

I have a nodeJS + expressJS + Angular2-RC.5 based site which works fine on my local Windows 10 machine. However, when I try to deploy (here's the log) to Heroku and access the site, the front end console (Chrome) throws the following error and the site doesn't load. It seems there is some issue with RXjs not being served on Heroku?

zone.js:101 GET https://ns-docs.herokuapp.com/node_modules/rxjs/RX.js 404 (Not Found)

enter image description here

my systemjs.config.js contains this:

(function(global) {
  // map tells the System loader where to look for things
  var map = {
    'app':                        '/app', // 'dist',
    '@angular':                   '/node_modules/@angular',
    'angular2-in-memory-web-api': '/node_modules/angular2-in-memory-web-api',
    'rxjs':                       '/node_modules/rxjs'
  };
  // packages tells the System loader how to load when no filename and/or no extension
  var packages = {
    'app':                        { main: 'main.js',  defaultExtension: 'js' },
    'rxjs':                       { defaultExtension: 'js' },
    'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
  };

  System.config(config);
})(this);

and my index.html contains:

...
    <script src="/node_modules/core-js/client/shim.min.js"></script>
    <script src="/node_modules/zone.js/dist/zone.js"></script>
    <script src="/node_modules/reflect-metadata/Reflect.js"></script>
    <script src="/node_modules/systemjs/dist/system.src.js"></script>
    <!-- 2. Configure SystemJS -->
    <script src="/config/systemjs.config.js"></script>
    <script>
      System.import('app').catch(function(err){ console.error(err); });
    </script>
    <base href="/">
</head>

So if I run the project locally, http://localhost:3000/node_modules/rxjs/RX.js shows the js source. However, if I push the project to Heroku, with this build log, that version returns a 404 on /node_modules/rxjs/RX.js

Update:

If I clone my repo to a new location on my machine, cd to the project root, run npm i , then git submodule update --init" thennode ./bin/www` then the project runs fine on localhost. I presume this means that all the info in the repo is sufficient to get the project functional. So my suspicion is still that it is something to do with the way my static asses are being served on Heroku vs. my local machine.

Upvotes: 1

Views: 400

Answers (1)

Poul Kruijt
Poul Kruijt

Reputation: 71891

Well the server is probably linux based and there the file/folder names are case sensitive. It's Rx.js not RX.js. So you've got a wrong import somewhere

Upvotes: 3

Related Questions