I npm installed the node-term-ui package, but I keep getting "Unexpected string" errors, then I noticed the syntax in the files looks different, and realized it's CoffeeScript which I've never used before.
How do I make it work?
zeMirco's answer is correct, but let me add more info: What node-term-ui
is doing is very, very unusual. The author has set main
in their package.json
to point to a .coffee
file, rather than compiling that file to a .js
file. They also haven't noted this in their README. I see that there's now discussion about this at https://github.com/jocafa/node-term-ui/issues/2.
The need for a .js
file may not have occurred to the author because, if you're running a .coffee
file, you can require
other .coffee
files. In fact, all you need to require .coffee
files directly is to require the coffee-script
module first. So what you could do in your JS file is:
require('coffee-script');
var TermUI = require('node-term-ui');
Be sure to add coffee-script
as a project dependency first.
I hope the author will modify the library so that CoffeeScript isn't required to use it, but that workaround should be easier than zeMirco's solution of compiling the module manually.
Just compile it into javascript
npm install -g coffee-script
coffee --compile TermUI.coffee // assuming you are inside the modules main folder
and then instead of requiring the module require the created TermUI.js
file
var termui = require('./node_modules/node-term-ui/TermUI.js')