Jose
Jose

Reputation: 599

Cakefile not requiring *.coffee files

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?

Upvotes: 0

Views: 248

Answers (2)

Jose
Jose

Reputation: 599

Solved by adding:

require 'coffee-script/register'

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

Upvotes: 3

c0d3junk13
c0d3junk13

Reputation: 1162

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

  require "#{__dirname}/test"

Upvotes: 0

Related Questions