systemjs / plugin-css

CSS loader plugin
MIT License
92 stars 60 forks source link

Error importing css from node #105

Closed dinoboff closed 8 years ago

dinoboff commented 8 years ago

Using jspm 0.17.0-beta-27 and something like that (for running test with mocha):

const jspm = require('jspm');
const loader = new jspm.Loader();

loader.import('my-package/some.css!').then(x => console.log(x)).catch(e => console.error(e))

I get:

{ (SystemJS) document is not defined
  ReferenceError: document is not defined
      at SystemJSNodeLoader.CSSPluginBase.instantiate (/path/to/jspm_packages/github/systemjs/plugin-css@0.1.27/css-plugin-base.js:60:15)
      at /path/to/jspm_packages/github/systemjs/plugin-css@0.1.27/css.js:121:34
  Error loading /path/to/src/some.css!/path/to/jspm_packages/github/systemjs/plugin-css@0.1.27/css.js
  originalErr:
   ReferenceError: document is not defined
       at SystemJSNodeLoader.CSSPluginBase.instantiate (file:///path/to/jspm_packages/github/systemjs/plugin-css@0.1.27/css-plugin-base.js:60:15)
       at file:///path/to/jspm_packages/github/systemjs/plugin-css@0.1.27/css.js:121:34 }

I would expect the loader to just ignore the import.

dinoboff commented 8 years ago

A workaround it to map "css" to plugin-text in the node config (is there better a way?).

guybedford commented 8 years ago

Yes it would definitely be better to not have this error in Node.

guybedford commented 8 years ago

Added in https://github.com/systemjs/plugin-css/commit/8ec7a565dffc2cb0ebd9505d30984800846e24e2.

dinoboff commented 8 years ago

Tested with 67d7f0e8 and it's working.

guybedford commented 8 years ago

Thanks for the follow-up here.