简体   繁体   English

Node.js无法识别Coffeescript

[英]Node.js not recognizing Coffeescript

I am currently trying to get into NodeJS together with the SailsJS framework. 我目前正在尝试与SailsJS框架一起使用NodeJS。 And I want to use coffeescript on the serverside aswell, but after converting all files in config/*.js to config/*.coffee properly with js2coffee, I get the following error when trying to start up the app: 我也想在服务器端使用coffeescript,但是在使用js2coffee将config/*.js 。js中的所有文件正确转换为config/*.coffee 。coffee之后,尝试启动应用程序时出现以下错误:

config/400.coffee config / 400.coffee

SyntaxError: Unexpected token ILLEGAL

pointing to the first character in the file, which is a hashtag for a coffee comment. 指向文件中的第一个字符,它是咖啡注释的主题标签。 So it seems the app does not recognize the file as coffeescript, but searching for standard js instead. 因此,似乎该应用程序无法将文件识别为coffeescript,而是搜索标准js。

I tried installing the package coffee-script and requireing it in 我尝试安装软件包coffee-script并要求将其放入

app.js app.js

require('coffee-script');
require('sails').lift(require('optimist').argv);

but it doesn't help. 但这没有帮助。

If I delete 400.coffee , the error appears in the next file 403.coffee etc. 如果我删除400.coffee ,则错误出现在下一个文件403.coffee等中。

What am I doing wrong? 我究竟做错了什么? Isn't coffeescript allowed in the config files or am I missing something? 配置文件中是否不允许coffeescript或我缺少什么?

Coffeescript 1.7.0, released Jan 28th, 2014, changed the require('coffee-script') behavior to only load the compiler itself. 2014年1月28日发布的Coffeescript 1.7.0更改了require('coffee-script')行为,仅加载了编译器本身。 Now, do load the automatic compiler for .coffee files, you must call require('coffee-script/register') before loading any coffeescript files. 现在,要为.coffee文件加载自动编译器,必须在加载任何coffeescript文件之前调用require('coffee-script/register')

Keep in mind that using this will mean that every .coffee file will be recompiled every time you start node , which could increase startup times. 请记住,使用此选项将意味着每次启动node时都会重新编译每个.coffee文件,这可能会增加启动时间。 That may or may not be important to you though. 但这对您可能并不重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM