J King
J King

Reputation: 4434

can not get MAP to work within system.config packages for SystemJS

Hello I have the following config set up for systemJS:

    System.config({
    packages: {
        //sets the root path of the Angular2 App
        'DesktopModules/RegentDMS/app': {
            //module format expected in application, register = System.register or System.registerDynamic compatibility module format
            format: 'register',
            //default file extension for paths
            defaultExtension: 'js',
            map: {'./app' : './DesktopModules/RegentDMS/app'}
        },
    } 
  }); 
System.import('app/boot')
        .then(null, console.error.bind(console));

The default extension works fine but I get is a 404 error in the console that says:

GET http://localhost:81/app/boot 404 (Not Found)

But if I change it to the following:

    System.config({
    packages: {
        //sets the root path of the Angular2 App
        'DesktopModules/RegentDMS/app': {
            //module format expected in application, register = System.register or System.registerDynamic compatibility module format
            format: 'register',
            //default file extension for paths
            defaultExtension: 'js'
        },
    } 
  }); 
System.import('/DesktopModules/RegentDMS/app/boot.js')
        .then(null, console.error.bind(console));

Then it does work.

QUESTION:

how can I set up the MAP setting so that I can use the short hand app/ to refer to the absolute path of DesktopModules/RegentDMS/app in import statements like app/boot (meaning DesktopModules/RegentDMS/app/boot.js)

Thanks

EDIT #1:

So i changed the ./app to app as suggested and tried both of the following:

 map: { 'app': './DesktopModules/RegentDMS/app' }
 map: { app: './DesktopModules/RegentDMS/app' }

and this does not work when using any of the following import statements:

System.import('app/boot')
 System.import('./app/boot')

I get the following error for both:

http://localhost:81/app/boot 404 (Not Found)

SOLUTION:

Move the map declaration to the config object like so:

    System.config({
    packages: {
        //sets the root path of the Angular2 App
        'DesktopModules/RegentDMS/app': {
            //module format expected in application, register = System.register or System.registerDynamic compatibility module format
            format: 'register',
            //default file extension for paths
            defaultExtension: 'js'
        }
    },
    map: { 'app': './DesktopModules/RegentDMS/app' }
  }); 
System.import('app/boot')
        .then(null, console.error.bind(console));

Upvotes: 4

Views: 6853

Answers (1)

Sasxa
Sasxa

Reputation: 41254

As @Langley suggested in comment, you should use app, not ./app (name not path), and move map definitions from packages object to the config object.

The map option ... allows you to map a module alias to a location or package:

https://github.com/systemjs/systemjs/blob/master/docs/config-api.md#map

Upvotes: 5

Related Questions