节点不需要* .coffee文件 [英] Node not requiring *.coffee files

查看:168
本文介绍了节点不需要* .coffee文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 http://stackoverflow.com/a/4769079/347915 ,我应该能够要求来自.js文件的.coffee文件:

According, to http://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

但是,当我这样做,我得到这个消息,当运行test.js:

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

我使用NVM安装的节点0.10.25。

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

推荐答案

由于Coffeescript 1.7.0,所需的库已更改。现在您必须使用:

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

require('coffee-script/register');

查看更改日志: http: //coffeescript.org/

这篇关于节点不需要* .coffee文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆