3

I want to remove .js suffix from Angular imports.

Not wanted (now workable): import { Example } from './whatever/example.js';

Wanted: import { Example } from './whatever/example';

I suspect I am missing a configuration in the systemjs.config.js.

(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': '/node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      'app': 'app',

      // angular bundles
      // other libraries

    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      }
    }
  });
})(this);
2
  • have you tried using defaultJSExtensions: true in your System.config(...? Commented Jun 7, 2017 at 13:26
  • @Wernerson Yes, it is not working. zone.js:2224 GET localhost:8000/app/whatever/example 404 (Not Found) Commented Jun 7, 2017 at 13:28

1 Answer 1

3

Try adding this in packages:

'.': {
    defaultJSExtensions: 'js'
}

Such that packages now looks like:

// packages tells the System loader how to load when no filename and/or no extension
packages: {
'.': {
    defaultJSExtensions: 'js'
},
app: {
    defaultExtension: 'js'
},
rxjs: {
    defaultExtension: 'js'
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.