0

I have the following files:

Cakefile:

require './test'

test.coffee:

console.log 'hi'

another_test.coffee:

require './test'

If I run cake, I get the following exception:

module.js:340
    throw err;
          ^
Error: Cannot find module './test'
  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/Cakefile:2:3)
  at Object.<anonymous> (/Users/jose/Desktop/Cakefile:4:4)
  at Module._compile (module.js:456:26)

However, if I run coffee another_test.coffee, I get this output:

hi

I installed node using brew and coffee-script using npm, and am using the following versions:

$ node -v
v0.10.24
$ npm -v
1.3.21
$ coffee -v
CoffeeScript version 1.7.1

Why can't Cakefile require test.coffee?

Jose
  • 609
  • 1
  • 7
  • 15
  • I think it's because of node not being able to require .coffee files (as cake is a .js script itself), so I've opened a different question: http://stackoverflow.com/questions/21677931/node-not-requiring-coffee-files – Jose Feb 10 '14 at 13:04

2 Answers2

3

Solved by adding:

require 'coffee-script/register'

on top of Cakefile. See: https://stackoverflow.com/a/21678007/347915

Community
  • 1
  • 1
Jose
  • 609
  • 1
  • 7
  • 15
0

Have you tried using an absolute path ? Try this instead :

  require "#{__dirname}/test"
c0d3junk13
  • 1,162
  • 9
  • 6
  • Thx, no luck, same error. Also, Cakefile is able to require a ./test.js file, so it doesn't look like a path problem, more like an extension thing. – Jose Feb 10 '14 at 12:10