Reputation: 18825
I have a Meteor project where I use coffeescript.
I'm not sure what has happened, but suddenly my solution is getting this error.
ReferenceError: share is not defined
at app/models/Models.js:3:3
when I try to boot up my solution.
It generates this error wherever I use the Meteor coffeescript share variable.
I'm using WebStorm and I have a FileWatcher to transpile coffeescript into javascript. When I turn this on (which I need to be able to debug in WebStorm), it generates .js and .map files for my .coffee files.
So somehow these generated JS files do not have a reference to the share variable that coffeescript uses in Meteor to have global variables.
I've tried to delete the .idea directory and the .meteor directory, I've tried adding and removing the meteor coffeescript package. I even tried to create a new solution - I still have the same problem.
I can't seem to fix it so that there is no error when the file watcher is turned on.
What is the source of this error and what can I do to fix it?
Upvotes: 0
Views: 628
Reputation: 93748
Meteor does a special job when compiling coffeescript to js: it prepends the generated code with
__coffeescriptShare = typeof __coffeescriptShare === 'object' ?
__coffeescriptShare : {};
var share = __coffeescriptShare;
to ensure that global __coffeescriptShare exists and is assigned to a file-scope variable share.
But the standard CoffeeScript compiler used in a file watcher knows nothing about these meteor tricks. As a result, we get
(function() {
share.TestFunction = function(p) {
return p;
};
}).call(this);
instead of
function(){__coffeescriptShare = typeof __coffeescriptShare === 'object' ? __coffeescriptShare : {}; var share = __coffeescriptShare;
share.TestFunction = function(p) {
return p;
};
})();
So the standard compiler is not suitable for transpiling coffeescript meteor applications. Meteor coffeescript package has to be used instead. It supports source maps, so there are no reasons for using file watchers. To me, debugging works when using maps produced by Meteor coffeescript package, but not always. Note that WebStyorm doesn't yet support meteor+coffeescript. Related tickets are: WEB-14479, WEB-14794
Upvotes: 1