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

standard less 1.1.5 not working with Java/Rhino, 1.1.4 was working #466

Closed
marceloverdijk opened this issue Nov 15, 2011 · 15 comments
Closed
Labels

Comments

@marceloverdijk
Copy link

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?

@marklagendijk
Copy link

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.

@marceloverdijk
Copy link
Author

ok, but I guess this is a bug in the latest less release related to the platform checks?

@marceloverdijk
Copy link
Author

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.
But when I remove Env.js I get the error: org.mozilla.javascript.EcmaError: ReferenceError: "window" is not defined. (less.js#8)

@marklagendijk
Copy link

Actually I don't know the code of less.js, I just noticed your issue and thought I might know what was causing it.
I assume you are already using the 'less-rhino-1.1.5.js' instead of 'less-1.1.5.js'?

Maybe someone else who is using Rhino with less.js can help?

@marceloverdijk
Copy link
Author

I also tried less-rhino-1.1.5 without any success.
Frustrating to notice have it working with 1.1.4 and replacing it with 1.1.5 it fails...

@cloudhead
Copy link
Member

Hmmmm I'll check the diff, see what could cause it.

@marceloverdijk
Copy link
Author

OK thanks. In the meantime I will check out if it would be better to switch to less-rhino.

@lukeholder
Copy link

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?

@kmchugh
Copy link
Contributor

kmchugh commented Jan 10, 2012

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.

@kmchugh
Copy link
Contributor

kmchugh commented Jan 10, 2012

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';
}

@marceloverdijk
Copy link
Author

@kmchugh Thanks, your fix also works for me!

@cloudhead What do you think about this fix? Could this be added to future releases?
Besides that I wonder what the future is for the less-rhino dist.. More people have problems with this and it is causing confusion. I noticed that for 1.2.0 there is also no less-rhino dist, is it discontinued?

@kmchugh
Copy link
Contributor

kmchugh commented Jan 10, 2012

No problem @marceloverdijk I've created pull request #557 for this.

@cloudhead
Copy link
Member

Hmm I have no idea how any of the rhino stuff works—you tell me what's best.

cloudhead pushed a commit that referenced this issue Jan 10, 2012
@marceloverdijk
Copy link
Author

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).
With the fix mentioned by @kmchugh less.js in combination with Rhino is working again.

I would say go for it.

PS: the less-rhino.js is a complete different story as this never worked for me.

@lukeapage
Copy link
Member

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.

stefanklug pushed a commit to stefanklug/carto that referenced this issue Jan 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants