Compiling Roy to JS fails: SourceMapGenerator undefined

60 views
Skip to first unread message

Andreas Hartmann

unread,
Oct 14, 2012, 9:01:33 AM10/14/12
to roy...@googlegroups.com
Hi Brian, hi all,

first of all, thanks for your great work!

I checked out Roy from github, but when I'm trying to compile a Roy file to JS, I get the following error:

roy -r examples/helloworld.roy

compile.js:817
        var sourceMap = new SourceMapGenerator({file: path.basename(outputPath
                        ^
TypeError: undefined is not a function
    at main (compile.js:817:25)
    at Array.forEach (native)
    at Function._.each._.forEach (/Volumes/Data/src/roy/roy/node_modules/underscore/underscore.js:74:11)
    at Object.main (/Volumes/Data/src/roy/roy/src/compile.js:803:7)
    at Object.<anonymous> (/Volumes/Data/src/roy/roy/roy:2:26)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)


It looks like the source-map module is not properly loaded.
Thanks a lot in advance for any hints!

-- Andreas

Andreas Hartmann

unread,
Oct 14, 2012, 10:31:22 AM10/14/12
to roy...@googlegroups.com
It seems to be related to a change in RequireJS 2.1.

More info: https://github.com/jrburke/requirejs/issues/490

This workaround helps:

        var oldSetTimeout = setTimeout;
        setTimeout = undefined;
        var SourceMapGenerator = require('source-map').SourceMapGenerator;
        setTimeout = oldSetTimeout;

Brian McKenna

unread,
Oct 15, 2012, 11:01:11 AM10/15/12
to roy...@googlegroups.com
That is very strange. I just got a new work computer so I did a clean
install of Roy and I have no problem with the source-map module.

Can you let me know what version of node.js you have and what version
of source-map got installed?

Andreas Hartmann

unread,
Oct 15, 2012, 1:43:11 PM10/15/12
to roy...@googlegroups.com
node.js: v0.8.11
source-map: 0.1.0

IIUC the problem lies in node_modules/source-map/node_modules/requirejs/require.js:

    /**
     * Execute something after the current tick
     * of the event loop. Override for other envs
     * that have a better solution than setTimeout.
     * @param  {Function} fn function to execute later.
     */
    req.nextTick = typeof setTimeout !== 'undefined' ? function (fn) {
        setTimeout(fn, 4);
    } : function (fn) { fn(); };

The code within the module is executed asynchronously. Since the source-map module is required inline in compile.js (as opposed to using a callback), the code within the module is not executed before the execution in compile.js is resumed, leading to undefined properties in the "exports" object.

Katie Miller

unread,
Nov 5, 2012, 8:21:20 PM11/5/12
to roy...@googlegroups.com
I just installed Node and Roy and I get the same stack trace.

node.js version: 0.8.14
source-map version: 0.1.0

Dominic Bou-Samra

unread,
Nov 28, 2012, 5:17:56 AM11/28/12
to roy...@googlegroups.com
Hmm, I sent a pull request earlier with the latest source-map version in the dependencies. I probably should have read this thread before, and actually tried to figure out why there error was occurring. Hopefully nothing is broken with the new version.

Andreas Hartmann

unread,
Dec 28, 2012, 8:14:48 AM12/28/12
to roy...@googlegroups.com
Thanks! With the new source map version 0.1.8 in HEAD the error doesn't occur anymore.
Reply all
Reply to author
Forward
0 new messages