0

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

Cristian Muscalu
  • 9,007
  • 12
  • 44
  • 76

3 Answers3

1

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,

Community
  • 1
  • 1
Daniel Pliscki
  • 1,913
  • 16
  • 24
0

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));
Nibin
  • 3,922
  • 2
  • 20
  • 38
  • The path is `C:\wamp\www\ngProject\app\boot.js` – Cristian Muscalu May 31 '16 at 12:57
  • Yes,The localhost is pointed to the C:\wamp\www\ folder right..? – Nibin May 31 '16 at 13:03
  • Cris, Angular has to be hosted on the "server" so try to think of paths as "whateverURL"/path/to/file instead of how it actually is locally. I say that because often server setups MASK the local file system, which is often the case in Angular2 seeds. For example, my seed converts: /GIT/project/src/client/app to: localhost – Dennis Smolek May 31 '16 at 13:08
0

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..

Community
  • 1
  • 1
Dennis Smolek
  • 8,480
  • 7
  • 30
  • 39
  • I tried changing `DocumentRoot "c:/wamp/www/ngProject" ` and even `DocumentRoot "c:/wamp/www/ngProject/app" ` but has no effect. Even my php projects work as usual from www folder. – Cristian Muscalu May 31 '16 at 13:55
  • I read about other ways (like Angular2 WebpackStarter or Angular2-Seed , that can turn all js into 1 and minify it, but i couldn't figure out how to make it work... – Cristian Muscalu May 31 '16 at 13:58