相关疑难解决方法(0)

require()来自JavaScript文件或REPL的CoffeeScript文件

我正在使用Node.js并希望将CoffeeScript合并到我的工作流程中.我有两个用例:

  1. 我希望能够编写哪些require()CoffeeScript模块的JavaScript文件
  2. 我希望能够从节点REPL中加载CoffeeScript模块

对于情况#1:我可以从编译.coffee.jsrequire().js模块,作为一种解决方法.

对于案例#2:现在我正在eval()输出coffee-script.compile().

有没有更好,更统一的方法来做到这一点?

javascript node.js coffeescript

53
推荐指数
2
解决办法
3万
查看次数

不能要求本地CoffeeScript模块

我正在运行Node.js 0.10.21.我尝试了两种CoffeeScript 1.6.3,无论是否使用require('coffee-script/extensions').将这两个文件编译为JavaScript并直接在Node中运行它们当然可以正常工作.

# ./folder/a.coffee
require('../b').test()

# ./b.coffee
exports.test = -> console.log 'yay'

# $ coffee folder/a.coffee
#
# Error: Cannot find module '../b'
#   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/test/folder/a.coffee:1:1)
#   at Module._compile (module.js:456:26)
Run Code Online (Sandbox Code Playgroud)

node.js coffeescript

3
推荐指数
1
解决办法
4432
查看次数

标签 统计

coffeescript ×2

node.js ×2

javascript ×1