less.js icon indicating copy to clipboard operation
less.js copied to clipboard

Conflicts with requirejs

Open joshuaspence opened this issue 13 years ago • 17 comments

The latest version (1.5.0) of less.js conflicts with require.js (if loaded before require.js), causing the following error:

Uncaught TypeError: Object function require(a){return window.less[a.split("/")[1]]} has no method 'config'

It seems that this is only an issue with the minified version (less-1.5.0.min.js) because the minified JavaScript is not wrapped in an anonymous closure. Adding function(){ to the beginning and }()) to the end of the minified file.

joshuaspence avatar Oct 28 '13 02:10 joshuaspence

Thankd, we updated our build system and must have broken this. I will fix this and do a new release soon.

lukeapage avatar Oct 28 '13 04:10 lukeapage

Did we get a fix on this yet? I seem to have stumbled across the same issue.

Fasani avatar Nov 11 '13 12:11 Fasani

I can confirm that I can get this working by using the non minified version, using the following code after my call to the require.js script:

<link rel="stylesheet/less" type="text/css" href="css/base.less" />
<script type="text/javascript">
less = {
      env: "development",
      async: false,
      fileAsync: false,
      poll: 1000,
      functions: {},
      dumpLineNumbers: "comments",
      relativeUrls: false
  };
</script>
<script src="js/libs/less-1.5.0.js" type="text/javascript"></script>

I still get an error but for development reasons I can continue to work and I will use NPM to finalise the code for live.

Uncaught Error: Mismatched anonymous define() module: function () { return less; }
http://requirejs.org/docs/errors.html#mismatch 

Fasani avatar Nov 11 '13 12:11 Fasani

Also seeing this issue.

shapeshed avatar Nov 12 '13 11:11 shapeshed

Seeing it as well.

javruben avatar Nov 14 '13 14:11 javruben

This is high priority to fix, will look at it next when I have time.

lukeapage avatar Nov 16 '13 08:11 lukeapage

I have the same issue. Did you need help for debug?

M3kH avatar Nov 16 '13 17:11 M3kH

There is a pull request open with a fix.. I have a couple of questions and then will merge if I get the right answers.

lukeapage avatar Nov 16 '13 22:11 lukeapage

Sorry to be the bearer of unhappy news, but still not seeing it fixed here with 1.5.1.

Fail cases using require.js 2.1.9:

  • Using less.js, lots of errors of missing modules in require (Uncaught TypeError: Cannot call method 'appendChild' of null and Uncaught TypeError: Object #<Object> has no method 'module'.
  • Using less.min.js, Uncaught Error: Mismatched anonymous define() module: function (){return w} in require.js, line 8.

Fail cases using require.min.js 2.1.9:

  • Using less.js, same as above - lots of errors of missing modules in require (Uncaught TypeError: Cannot call method 'appendChild' of null, Uncaught TypeError: Object #<Object> has no method 'module'.
  • Using less.min.js: Uncaught TypeError: Object function require(a){return window.less[a.split("/")[1]]} has no method 'config' when calling require.config

As before, all the code works great without less.js.

skoczen avatar Nov 18 '13 16:11 skoczen

Are you sure you updated?

https://github.com/less/less.js/blob/master/dist/less-1.5.1.min.js

we don't even have a function require any more...

lukeapage avatar Nov 18 '13 17:11 lukeapage

Yep - and require's definitely in https://github.com/less/less.js/blob/master/dist/less-1.5.1.js.

skoczen avatar Nov 18 '13 17:11 skoczen

But look at the 1.5.1 min file and look at your error - its the text from 1.5.0 also the non minified version was never broken.

lukeapage avatar Nov 18 '13 18:11 lukeapage

Apologies, copypasta between the versions. Using less.min.js 1.5.1 and require.min.js 2.1.9, I get:

Uncaught Error: Mismatched anonymous define() module: function (){return w} in require.min.js line 8.

For clarity, this is when including less.js directly in the page, not loading it through require. Loading it through require.js works fine with the new version (and since it solves my problem and I'm not 100% sure of the dependencies / ordering when doing the inline pattern, I'm fine with saying this is not a bug.)

Thanks for the quick response, and apologies for the error!

skoczen avatar Nov 18 '13 19:11 skoczen

I have had the same problem, but less-1.5.1.js (not minified, didn't try the other) fixed it.

I include it like this: link rel="stylesheet" type="text/css" href="styles/screen.less" media="screen" script src="javascript/lib/less-1.5.1.js" type="text/javascript" script data-main="javascript/app" src="javascript/lib/requirejs-2.1.9.js"

(removed tags)

don't know what skoczen faces for a problem, but for me it works.

grobmeier avatar Nov 20 '13 14:11 grobmeier

@skoczen Read this. If you don't want to include less.js using Require.js API, try including the less.js before require.js as @grobmeier commented.

joseadrian avatar Nov 25 '13 23:11 joseadrian

Including the less.js before require.js does not resolve the issue for me. I've resorted to using the un-minified version.

james-gardner avatar Dec 16 '13 12:12 james-gardner

For me it works when using the not minified version of less less-1.5.1.js and including it bevor require.js is loaded:

works very fine and is absolutely fast...

ghost avatar Dec 16 '13 23:12 ghost