【问题标题】:Cakefile not requiring *.coffee filesCakefile 不需要 *.coffee 文件
【发布时间】:2014-02-10 11:25:09
【问题描述】:

我有以下文件:

蛋糕文件:

require './test'

test.coffee:

console.log 'hi'

another_test.coffee:

require './test'

如果我运行 cake,我会得到以下异常:

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)

但是,如果我运行 coffee another_test.coffee,我会得到以下输出:

hi

我使用 brew 和 coffee-script 使用 npm 安装了节点,并且正在使用以下版本:

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

为什么 Cakefile 不能要求 test.coffee?

【问题讨论】:

标签: coffeescript cakefile


【解决方案1】:

通过添加解决:

require 'coffee-script/register'

在 Cakefile 之上。见:https://stackoverflow.com/a/21678007/347915

【讨论】:

    【解决方案2】:

    您是否尝试过使用绝对路径?试试这个:

      require "#{__dirname}/test"
    

    【讨论】:

    • 谢谢,不走运,同样的错误。此外,Cakefile 能够要求一个 ./test.js 文件,所以它看起来不像是路径问题,更像是一个扩展。
    猜你喜欢
    • 2014-03-07
    • 2014-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多