Coffeescript not defined on the client

Hi,

I’m using CoffeeScript on some server-files; no problem… (it is installed with the Meteor Package).
But if I try to compile a piece of coffeescript on the client, an error says:
CoffeeScript not defined.
Do I need to include it separate if I need to compile clientside?
And if so, what package?
import { CoffeeScript } from ‘coffeescript’;
gives an error: Error: Cannot find module ‘coffeescript’

regards,

Paul

Hm. By now, I found out that there is a separate package, coffeescript-compiler, but after installing that, I still get the same error… anybody using CoffeeScript to compile live code? :slight_smile:
regards,

Paul

The coffeescript Meteor package compiles code on the client and server, there is no need to import it. Or are you trying to compile some code you read from the database or as an asset? In that case (I have not tried it) to import from a Meteor package you need to prepend meteor like import { CoffeeScript } from ‘meteor/coffeescript’.

Hi @softwarerero,

Thank you for your answer!

Yes; I’m trying to compile from an input, ao I need to compile clientside.
I tried import { CoffeeScript } from ‘meteor/coffeescript’, but I get the error: CoffeeScript.compile is not a function
Although I am not certain what you mean by “prepend meteor”? I just put the import on top of my template-code.

regards,

Paul

I meant exactly what you did but I see it doen’t work.

import CoffeeScript from '/node_modules/coffeescript/lib/coffeescript' worked for me.

There may be a better way when we could see what the Meteor coffeescript package exports, but the links on Atmosphere are dead and I cannot not find the source code.

Hmm…

I have the package on my computer, now, of course, can you point me to how I can find out what the export / import call needs to be?
For instance I found
module.export({ CoffeeScriptCompiler: () => CoffeeScriptCompiler });
But if I try import {CoffeeScriptCompiler} from ‘CoffeeScriptCompiler’ it cannot find the package :frowning:
I’m not familiar with the way to build/import a packge, as normally Meteor takes care of that…

regards,

Paul

What error do you get when you do the import or use CoffeeScript.compile later?

Hi @softwarerero

it says in the console:

For now, I have “solved” the problem by putting a separate coffeescript.js in de /client/js folder - and now it works. But I would prefer not to have to do this, as it probably means the client is downloading this twice?..

regards,

Paul

You won’t need to include coffeescript.js twice in you bundle. You should find it somewhere in the node_modules directory. Just grep for it and adapt the path a little.

With import CoffeeScript from ‘/node_modules/coffeescript/lib/coffeescript’ for me CoffeeScript.compile definitly compiles.

Hi @softwarerero,

nope, cannot find it there. I guess that is because I installed it as a meteor package, not NPM?

Paul

You are right, I created a new Meteor project, did meteor add coffeescript and all the coffescript files exist in the .meteor/local path nothing under npm_modules. I had the npm package installed as the dependency of another package.

So having the coffeescript.js in your client folder as you did works. Alternatively you could simply install the npm package. In both cases coffeescript.js exists only once in the bundle, I verified this.

Hi, I maintain CoffeeScript. The Meteor coffeescript package is for Meteor’s build pipeline, to handle .coffee files in your project; it’s not used at runtime, either server- or client-side.

If you want to be able to compile CoffeeScript source code at runtime, use the coffeescript npm package: meteor npm install coffeescript. Then just import CoffeeScript from 'coffeescript' wherever you want to run CoffeeScript.compile.

Yes the latter package is a dependency of the Meteor build pipeline package, but such dependencies aren’t designed to be accessible by runtime code; it would be unnecessary bloat for build plugins to be loaded at runtime. You should just install the runtime package in addition to the build one, assuming you need the build one at all.