Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要Node.js应用程序中的CoffeeScript会导致找不到模块错误_Node.js_Coffeescript - Fatal编程技术网

需要Node.js应用程序中的CoffeeScript会导致找不到模块错误

需要Node.js应用程序中的CoffeeScript会导致找不到模块错误,node.js,coffeescript,Node.js,Coffeescript,我试图从Node.js应用程序中获取CoffeeScript文件,但Node.js给出了错误错误:找不到模块'something'。正确的方法是什么?如果我事先编译CoffeeScript代码,它可以工作,但我不想这样做 test.js: require('coffee-script').register(); require('something'); 咖啡: console.log('Hello World!'); 控制台输出: > node test.js module.js

我试图从Node.js应用程序中获取CoffeeScript文件,但Node.js给出了错误
错误:找不到模块'something'
。正确的方法是什么?如果我事先编译CoffeeScript代码,它可以工作,但我不想这样做

test.js:

require('coffee-script').register();

require('something');
咖啡:

console.log('Hello World!');
控制台输出:

> node test.js

module.js:340
    throw err;
          ^
Error: Cannot find module 'something'
  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> (C:\Users\Sami\Desktop\smallscale\test.js:3: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:906:3
>node test.js
module.js:340
犯错误;
^
错误:找不到模块“something”
在Function.Module.\u解析文件名(Module.js:338:15)
在Function.Module.\u加载(Module.js:280:25)
at Module.require(Module.js:364:17)
根据需要(模块js:380:17)
反对。(C:\Users\Sami\Desktop\smallscale\test.js:3:1)
在模块处编译(Module.js:456:26)
在Object.Module.\u extensions..js(Module.js:474:10)
在Module.load(Module.js:356:32)
在Function.Module.\u加载(Module.js:312:12)
位于Function.Module.runMain(Module.js:497:10)
启动时(node.js:119:16)
在node.js:906:3

似乎您正试图
require()
使用
require()
模块结构的文件

如果您
require()
没有提供文件路径(绝对或相对),Node.js将在
/Node\u modules
目录中查找您的模块。您可以阅读文档

尝试将模块要求为JavaScript文件,如下所示:

require('./something')

(并确保
。/something'
是从您需要模块的位置到模块在您的应用程序结构中的位置的路径,或者使用绝对路径)。

您也反对编译该模块的监视过程?@DaveNewton我发现多个答案表明这应该是可能的。比如说,为什么不试试上面说的呢?我总是有一个监视程序在进行linting和编译,所以我并不真正了解按需编译——对不起。