首页 > 解决方案 > Node.js 检查选项

问题描述

命令行--check选项应该检查(错误)文件而不执行它,但它不起作用。

它工作了一两次,但现在情况并非如此,我是否遗漏了什么或者这可能不是正确的语法?

在 Windows 10 / PowerShell 上测试(具有管理员权限)

--- PowerShell command line
$ > node --check index.js                           // doesn't do anything (no error thrown)
$ > node -c index.js                                // doesn't do anything (no error thrown)
$ > node index.js --check                           // executes the file (prints 'module executed!' and throws a ReferenceError) 
$ > node index.js -c                                // executes the file (prints 'module executed!' and throws a ReferenceError) 
--- index.js file 
console.log( 'module executed!' );

myRefferenceError;                                  // ReferenceError                      

标签: node.jspowershell

解决方案


当然,node --check index.js(或)node -c index.js是执行标志的正确方法。

但是,根据文档,该标志似乎只会检查语法错误,并且不会检查超出您的情况发生的错误。

希望这可以帮助!


推荐阅读