2

I am trying to configure SystemJS for an existing AngularJS + Typescript application.

I have a problem with module loading: When I use this syntax:

import module1 from './path-to-module1'

TS compiler is happy but SystemJS will not find this module. After a little investigation I found this, on SystemJS documentation:

System.defaultJSExtensions = true;

// requests ./some/module.js instead
System.import('./some/module');

Cool, now both TS compiler and SystemJS work. But, SystemJS documentations says:

Note that this is a compatibility property for transitioning to using explicit extensions and will be deprecated in future.

So, I figured out that I should add a .js extention to my module loading, like this (removing the 'defaultJSExtensions = true' flag):

import module1 from './path-to-module1.js'

Now SystemJS knows how to load my module, by TS compiler says:

Cannot find module './path-to-module1.js'

How can I make TS figure this out? Should I manually add all my modules to a *.d.ts file? How?

10x!

EDIT

I found this post, which I guess should be what I need to do. I found this on my Grunt file:

typescript: {
      build: {
        src: ...,
        outDir: '...',
        reference: 'reference.ts',
        options: {
          target: 'es5',
          sourceMap: false,
          declaration: false,
          removeComments: false,
          experimentalDecorators: true,
          module: 'commonjs'
        }
      }
    }

But, changing the commonjs to system did not help hree..

1 Answer 1

2

Don't worry, the SystemJS documentation is a bit misleading... Once they remove the defaultJSExtension all you have to do it to mark your code directory as a package (In the systemJS configuration) You can read about it here

Anyway, the file name without the extension is a valid ES6 module import syntax, so SystemJS will have to support it, as I said they will support it using a different way in the configuration.

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.