Search code examples
systemjs

systemjs: mapping everything else to node_modules


I am having trouble getting systemjs to work so it resolves node modules.

I have the following in my index.html:

<script src="./system.config.js"></script>
<script>
    System.import('blast/test')
            .then(null, console.error.bind(console));
</script>

This is my configuration:

System.config({
    baseUrl: '/',
    packages: {
        'app': {
            defaultExtension: 'js',
        }
    },

    packageConfigPaths: ['./node_modules/*/package.json'],

    paths: {
        'blast/*': 'app/*'
    }
});

This works fine so far. However, I want to be able to also resolve node modules like lodash. So I set paths to this:

paths: {
    'blast/*': 'app/*'
    '*': './node_modules/*'
}

Now I can import lodash fine, but when importing blast/test I get the error /app/test 404 (not found). It seems, the package configuration isn't used anymore, this .js isn't appended. Anyone got any hints how to resolve this? I am using SystemJs 0.19.25 Standard.

Thanks, Robin


Solution

  • Try using map configuration here rather for your local package -

    System.config({
      map: {
        blast: './app'
      }
    });
    

    The ./ is necessary to distinguish the URL space from becoming the node_modules/app path (probably the reason you used paths here to begin with?)

    It's also advisable to use baseURL: 'node_modules' instead of a wildcard paths entry (and they pretty much amount to the same thing).