Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
samuelvogel opened this issue Sep 8, 2011 · 2 comments
Open

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

samuelvogel opened this issue Sep 8, 2011 · 2 comments

Comments

@samuelvogel
Copy link

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
Copy link
Author

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.

@danse
Copy link

danse commented Jun 7, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants