rolaveric / karma-systemjs

Karma plugin for using SystemJS as a module loader
MIT License
40 stars 19 forks source link

TypeError: System.import is not a function #71

Closed MikeCheel closed 8 years ago

MikeCheel commented 8 years ago

I'm trying to use karma-systemjs and been struggling to get things working (for 3 days or so now). I keep getting the error in the title of this issue. From what I can tell Karma is not loading system.js. I have tried adding it to paths, maps, and every other likely place I can think of but no luck. I have opened a stackoverflow post with screenshots and details. Any help would be appreciated.

http://stackoverflow.com/questions/35636823/systemjs-and-karmajs-typeerror-system-import-is-not-a-function

rolaveric commented 8 years ago

I see the problem. It's because you've got your bootstrapping code (eg. System.import() calls) inside your SystemJS config file - system.conf.js karma-systemjs expects just a simple System.config() call that it can then intercept to find out where your transpiler and polyfills are. It does this by evaluating your config file with a fake System object which simply records whatever is passed to System.config(). This fake object has no System.import() method, which causes your error.

I'd recommend moving your bootstrapping code into a separate file (I personally put it in a script tag with my HTML). Otherwise you'll run into similar problems if you try to use systemjs-builder, and you probably don't want angular.bootstrap() to be called at the start of your unit tests.

MikeCheel commented 8 years ago

Thanks for your response as it has cleared up a lot! I really appreciate it.