requirejs/require-cs

IcedCoffeeScript is not supported

Closed this issue · 3 comments

When I try to use require-cs with IcedCoffeeScript (http://maxtaco.github.com/coffee-script/extras/coffee-script.js), I get the following javascript error:

Uncaught Error: Mismatched anonymous define() module: function (){return CoffeeScript.iced}

This is because IcedCoffeeScript for some reason defines two anonymous modules instead of one.

Although this error does not prevent CoffeeScript from loading and compiling normally, there's another ICS-specific issue:

Whenever a .coffee file contains ICS keywords (defer, await), there is the following error thrown:

Module name 'iced-coffee-script' has not been loaded yet for context: _

This is because ICS adds this line to the JS code:

  iced = require('iced-coffee-script').iced;

It by default assumes that it is in node mode. When I try to override ICS's runtime mode like this:

require.config({
    CoffeeScript: {
        runtime: 'inline' // or 'window'
    },
// [...]

It stops adding the require line, but I start getting the following errors everywhere:

"__extends is not defined"

I couldn't find out why this happens.

The first problem should be taken to the iced cs developer, seems like it should just have the define() only for the .iced return value and not have the one for CoffeeScript.

It also sounds like for the 'iced-coffee-script' require() injection that the developer should not do that in an amd environment, or do it in a different way. Maybe a shim module is provided for iced-coffee-script.js that just has a define()'d module that has CoffeeScript as a dependency and then return the .iced property from it?

But in general, it is difficult to see how to get this work since the project just tacks things onto the coffeescript code. It may be better to start a different loader plugin for it if the other issues are resolved.

For anyone (like me) looking for a fix to this, the config values needed for IcedCoffeeScript are described in this issue and they can be set like this:

require.config({
  CoffeeScript: {bare: true, runtime:'inline'}
});
// first require:
require ...

As of now, Require-CS supports IcedCoffeeScript.

FYI, the config option CoffeeScript: {bare: true, runtime:'inline'} appears to not be needed on my system with the newest version of ICS. In fact, when using it, I get a cryptic TypeError:

TypeError: In
{JS path}
Cannot call method 'assign' of null
In module tree:
  main
    app

This is a call to Scope.root.assign in nodes.coffee's utility() method. I am not sure why it ends up null at this point but removing the configuration option entirely fixed it for me.

To clarify - this error only occurred during r.js optimization. The error did not occur in the browser.

It appears that ICS is truly just a drop-in replacement at this point, no configuration needed.