systemjs / plugin-css

CSS loader plugin
MIT License
92 stars 60 forks source link

Error at runtime using plugin #114

Closed elsasslegend closed 7 years ago

elsasslegend commented 7 years ago

When using css plugin, I get at run time the following error :

Error: http://localhost:3000/app/widgets/message-area/message-area.css!http://localhost:3000/jspm_packages/github/systemjs/plugin-css@0.1.31.js detected as register but didn't execute.
    From previous event:
    From previous event:
    From previous event:
    From previous event:
    From previous event:
    From previous event:
        at Function.eval (eval at <anonymous> (http://localhost:3000/app/core/module-loader.js), <anonymous>:3:1)
        at eval (http://localhost:3000/app/core/module-loader.js:74:33)
    From previous event:
        at Function.ModuleLoader.loadModules (http://localhost:3000/app/core/module-loader.js:72:28)
        at eval (http://localhost:3000/app/core/dependency-injection-loader.js:42:61)
    From previous event:
        at Function.DependencyInjectionLoader.init (http://localhost:3000/app/core/dependency-injection-loader.js:40:26)
        at Function.Bootstrap.initializeApplication (http://localhost:3000/app/bootstrap.js:59:66)
        at Main (http://localhost:3000/app/main.js:97:56)
        at execute (http://localhost:3000/app/main.js:136:15)
    Error loading http://localhost:3000/app/widgets/message-area/message-area.css!http://localhost:3000/jspm_packages/github/systemjs/plugin-css@0.1.31.js as "./message-area.css!" from http://localhost:3000/app/widgets/message-area/viewmodel.js

The file where I'm loading the css from contains the following code (Typescript) viewmodel.js

import "./message-area.css!";
import { injectable } from "inversify";

@injectable()
export default class MessageArea {

    public glyph: string;
    public titleKey: string;
    public messageKey: string;

    public activate(setting: any) {
        this.glyph = setting.glyph;
        this.titleKey = setting.titleKey;
        this.messageKey = setting.messageKey;
    }
};

which transpiles to

System.register(["./message-area.css!", "inversify"], function(exports_1, context_1) {
    "use strict";
    var __moduleName = context_1 && context_1.id;
    var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    };
    var __metadata = (this && this.__metadata) || function (k, v) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
    };
    var inversify_1;
    var MessageArea;
    return {
        setters:[
            function (_1) {},
            function (inversify_1_1) {
                inversify_1 = inversify_1_1;
            }],
        execute: function() {
            MessageArea = (function () {
                function MessageArea() {
                }
                MessageArea.prototype.activate = function (setting) {
                    this.glyph = setting.glyph;
                    this.titleKey = setting.titleKey;
                    this.messageKey = setting.messageKey;
                };
                MessageArea = __decorate([
                    inversify_1.injectable(), 
                    __metadata('design:paramtypes', [])
                ], MessageArea);
                return MessageArea;
            }());
            exports_1("default", MessageArea);
            ;
        }
    }
});

The config.js looks like this :

meta: {
        (...)
        "*.css": { loader: 'css' },
(...)        
},
 map: {
        "css": "github:systemjs/plugin-css@0.1.31",

I cannot figure out what is the problem, since my configuration seems to be good. Am I missing something ? Is it possible that the loader plugin must be specified as "cjs" format ?

Thanks for your help :)

guybedford commented 7 years ago

This plugin provides a fetch hook that returns an empty string, which should just be interpreted as an empty module in the loader.

What loader are you using here? Ensure that it can support a plugin like that.

elsasslegend commented 7 years ago

I'm using System.JS as Loader, it should work. I notice that the module format returned by url/of/CSS/file.css!url/of/plugin.js is set to 'register'. Is this normal ?

elsasslegend commented 7 years ago

Found the Problem, another Meta declaration was overriding *.JS files to use 'register' as module format. Removed it and now it works. Thanks !