cssx icon indicating copy to clipboard operation
cssx copied to clipboard

css.js plugin makes RequireJS' r.js runs fail

Open samuelvogel opened this issue 14 years ago • 2 comments

When trying to optimize your app with r.js the optimizer fails when you include css! requires. The plugin should at least somehow silently do nothing on r.js runs instead of failing them. Later one could implement actual CSS packaging as well.

Tracing dependencies for: application

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
ReferenceError: document is not defined
    at Function.<anonymous> (eval at <anonymous> (/Users/samuelvogel/Viison/Workspace/GigalocalAdmin/r.js:7467:25))
    at Function.load (/Users/samuelvogel/Viison/Workspace/GigalocalAdmin/r.js:7467:25)
    at loadPaused (/Users/samuelvogel/Viison/Workspace/GigalocalAdmin/r.js:1144:25)
    at /Users/samuelvogel/Viison/Workspace/GigalocalAdmin/r.js:1186:25
    at Object.completeLoad (/Users/samuelvogel/Viison/Workspace/GigalocalAdmin/r.js:1452:17)
    at Function.load (/Users/samuelvogel/Viison/Workspace/GigalocalAdmin/r.js:7470:33)
    at loadPaused (/Users/samuelvogel/Viison/Workspace/GigalocalAdmin/r.js:1144:25)
    at /Users/samuelvogel/Viison/Workspace/GigalocalAdmin/r.js:1186:25
    at Object.completeLoad (/Users/samuelvogel/Viison/Workspace/GigalocalAdmin/r.js:1452:17)
    at Function.load (/Users/samuelvogel/Viison/Workspace/GigalocalAdmin/r.js:7470:33)

samuelvogel avatar Sep 08 '11 16:09 samuelvogel

The problem is caused by referencing document in the outer function call. Wrapping everything in if(typeof document != 'undefined') {...} solves this, and makes the plugin be ignored by r.js.

Obviously it would be nicer to restructure the code by some other means.

samuelvogel avatar Sep 08 '11 17:09 samuelvogel

i was trying your solution, and got the error:

TypeError: Cannot read property 'normalize' of undefined

looks related to the css plugin. normalize must be provided anyway as a noop, probably. I think i fixed the problem adding an else branch with a mock:

} else {
    define({
        normalize: function(){},
        load: function(){}
    });
}

the result is to have the plugin to be ignored, as you said

danse avatar Jun 07 '13 16:06 danse