Cristian Muscalu
Cristian Muscalu

Reputation: 9925

Angular2 unable to load boot.js

I can't get pass boot.js file when i run directly from: file:///C:/wamp/www/ngProject/index.html or from wamp : http://localhost/ngproject/

In develop mode it works with npm-start, but shouldn't it work with WAMP or just by running Index.html?

This is my system.js

  <script>
  System.config({
    packages: {        
      app: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
  System.import('app/boot')
        .then(null, console.error.bind(console));
</script>

When starting from wamp - Error: Unable to load script http://localhost/app/boot.js Error loading http://localhost/app/boot.js
When starting Index.html - Error: Unable to load script file:///app/boot.js Error loading file:///app/boot.js

Upvotes: 0

Views: 426

Answers (3)

Dennis Smolek
Dennis Smolek

Reputation: 8770

So when you use npm-start there is likely a server setup for your project for your seed. This will have all the config settings for the server that runs in your seed package.

If you used the angular2-seed which I love but can be slightly complicated with its options, the settings are in: tools/config/seed-config.ts

What this does is MAP to your root folder to load files.

Wamp by default maps localhost to c:\www but you actually want it to map to c:\www\ngProject

Think about it like this,

When you load /ngProject/index.html It says, "Ok, I need to load boot.js which is located at /app/boot.js"

but it's really at /ngProject/app/boot.js and it fails

You can either change your system to load from /ngProject in all your configs, or what I reccomend is adjust your wamp settings.

Instructions from this SO Answer:

For wamp 2.5 on Windows, use a text editor, e.g. notepad++ to edit c:\wamp\bin\apache\apache2.4.9\conf\httpd.conf

  1. Change DocumentRoot "c:/wamp/www" to DocumentRoot "c:/my/new/path" (Note slash direction). This will change the location where files are served from (~Line 230).
  2. Change to (Note slash direction). This applies permissions from the old directory to the new one (~Line 252).

Another thing, is MANY of the seed's also have a "Production" build which will automatically convert to a relative/base root path structure. That is something I'd check too..

Upvotes: 0

Nibin
Nibin

Reputation: 3960

Try checking your path to boot.js. When starting from wamp - Error: Unable to load script http://localhost/app/boot.js

Error loading http://localhost/app/boot.js

The path here seems to be wrong,because your js file is located

@ http://localhost/ngProject/app/boot.js

Something like this might hep you

For wamp server try this

 System.config({
            baseURL: 'ngProject'
        });

System.import('app/boot')
        .then(null, console.error.bind(console));

Upvotes: 0

Daniel Pliscki
Daniel Pliscki

Reputation: 1933

Basically you always need a http server to run an Angular application.

Take a look at this question. There are some pretty solid answers on why a http server is needed.

Why do I need a HTTP-server to run Angular 2?

Regards,

Upvotes: 1

Related Questions