-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
standard less 1.1.5 not working with Java/Rhino, 1.1.4 was working #466
Comments
This might be related to the new platform checks in less.js: if (typeof environment === "object" && ({}).toString.call(environment) === "[object Environment]") {
// Rhino
// Details on how to detect Rhino: https://github.com/ringo/ringojs/issues/88
less = {};
tree = less.tree = {};
less.mode = 'rhino';
} else if (typeof(window) === 'undefined') {
// Node.js
less = exports,
tree = require('./tree');
less.mode = 'rhino';
} else {
// Browser
if (typeof(window.less) === 'undefined') { window.less = {} }
less = window.less,
tree = window.less.tree = {};
less.mode = 'browser';
} The error says that less is undefined, therefore it seems likely that there is a problem with the platform check. Try adding a debug statement in the rhino check. If the code does recognize rhino properly the problem must be elsewhere. Edit: note that 'less.mode' is wrongly set to 'rhino' for node.js. This has been fixed, but according to @cloudhead it didn't break anything: #460. |
ok, but I guess this is a bug in the latest less release related to the platform checks? |
Yes, the check for Rhino evaluates to true if (typeof environment === "object" && ({}).toString.call(environment) === "[object Environment]") {
console.log("rhino");
// Rhino
// Details on how to detect Rhino: https://github.com/ringo/ringojs/issues/88
less = {};
tree = less.tree = {};
less.mode = 'rhino';
} as it prints out 'rhino'. But I wonder what this means? What is changed compared to the previous version. Note that I'm using Env.js to simulate the browser. |
Actually I don't know the code of less.js, I just noticed your issue and thought I might know what was causing it. Maybe someone else who is using Rhino with less.js can help? |
I also tried less-rhino-1.1.5 without any success. |
Hmmmm I'll check the diff, see what could cause it. |
OK thanks. In the meantime I will check out if it would be better to switch to less-rhino. |
I am not able to get less working on rhino. Is there a guide/docs? I see there is a special build in dist - what is the difference between that and less-rhino @marceloverdijk is talking about? |
I had 1.1.4 running on rhino as well, but can not get any newer versions running, with 1.1.5 and 1.2.0 I get the same errors as @marceloverdijk, with less-rhino-1.1.5.js the error is slightly different: org.mozilla.javascript.EcmaError: ReferenceError: "arguments" is not defined. I'm not going to look any further at the less-rhino, but I will try to get 1.2.0 working. |
The problem is related to how Rhino is being treated when the less environment is being set up. rhino does have a window object, so adding the code to assign less to window fixes the issues. EDIT : rhino does have a window object if you are using the asual lesscss engine, specifically browser.js where the object is created. Using the lesscss engine and the modification to the code here I've managed to get 1.2.0 working in rhino. var less, tree;
if (typeof environment === "object" && ({}).toString.call(environment) === "[object Environment]") {
// Rhino
// Details on how to detect Rhino: https://github.com/ringo/ringojs/issues/88
if (typeof(window) != 'undefined') { window.less = {} }
less = typeof(window) != 'undefined' ? window.less : {};
tree = less.tree = {};
less.mode = 'rhino';
} else if (typeof(window) === 'undefined') {
// Node.js
less = exports,
tree = require('./tree');
less.mode = 'node';
} else {
// Browser
if (typeof(window.less) === 'undefined') { window.less = {} }
less = window.less,
tree = window.less.tree = {};
less.mode = 'browser';
} |
@kmchugh Thanks, your fix also works for me! @cloudhead What do you think about this fix? Could this be added to future releases? |
No problem @marceloverdijk I've created pull request #557 for this. |
Hmm I have no idea how any of the rhino stuff works—you tell me what's best. |
I'm not a Rhino guru at all. All I can say is that after 1.1.4 Rhino support was broken (using less.js). I would say go for it. PS: the less-rhino.js is a complete different story as this never worked for me. |
since #557 was pulled and there are plenty other fix rhino bugs - closing this. If there is something missing not filed under the rhino label please shout. |
Using the standard less 1.1.4 dist I could use Java/Rhino to compile a less source.
When I use the latest less-1.1.5.js dist than I get the following error:
org.mozilla.javascript.EcmaError: TypeError: Cannot read property "tree" from undefined (less.js#13)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3785)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3763)
at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3791)
at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3810)
at org.mozilla.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3823)
at org.mozilla.javascript.ScriptRuntime.getObjectElem(ScriptRuntime.java:1457)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1428)
at script.require(less.js:13)
at script(less.js:1252)
at script(less.js:8)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3178)
at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
at org.mozilla.javascript.Context.evaluateReader(Context.java:1142)
when trying to:
cx.evaluateReader(scope, new InputStreamReader(lessJs.openConnection().getInputStream()), "less.js", 1, null);
(Where cx is the Mozilla Rhino Context object).
It seems Rhino is unable to compile the latest less.js...
Any ideas?
The text was updated successfully, but these errors were encountered: