Question

According, to https://stackoverflow.com/a/4769079/347915, I should be able to require a .coffee file from a .js file:

$ echo 'console.log "works"' > module.coffee

$ echo '
> require("coffee-script")
> require("./module")
> ' > test.js

$ node test.js
works

However, when I do that, I get this message when running test.js:

module.js:340
    throw err;
      ^
Error: Cannot find module './module'
  at Function.Module._resolveFilename (module.js:338:15)
  at Function.Module._load (module.js:280:25)
  at Module.require (module.js:364:17)
  at require (module.js:380:17)
  at Object.<anonymous> (/Users/jose/Desktop/pedo/test.js:2:1)
  at Module._compile (module.js:456:26)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Function.Module.runMain (module.js:497:10)
  at startup (node.js:119:16)
  at node.js:902:3

I'm using Node 0.10.25 installed using NVM. Also using CoffeeScript 1.7.1 installed using NPM 1.3.24.

Was it helpful?

Solution

Since Coffeescript 1.7.0, the required library changed. Now you have to use:

require('coffee-script/register');

See the changelog: http://coffeescript.org/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top