简体   繁体   English

Node.js无法编译已安装的测试之一

[英]Node.js can't compile one of the installed tests

I am trying to port a PHP project to node.js 我正在尝试将PHP项目移植到node.js

I installed node 0.10.26 using the universal installer for mac os x downloaded from node.org. 我使用从node.org下载的mac os x通用安装程序安装了节点0.10.26。 The path env contains the right dir paths to the executables..etc. 路径env包含可执行文件的正确目录路径。

I converted the first file/module, tried to check its syntax using 我转换了第一个文件/模块,尝试使用以下命令检查其语法

node - p ~/path/with/no/spaces/to/myFile.js

The result is an error that reads: 结果是显示以下错误:

Minis-Mac:Projects newbnz$ node -p ~/Projects/convert/application/models/mdAPI.js 
[eval]:1
/Users/maat/Projects/convert/application/models/mdAPI.js 
^
SyntaxError: Invalid flags supplied to RegExp constructor 'newbnz'
    at new RegExp (<anonymous>)
    at [eval]:1:1
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:532:25)
    at startup (node.js:80:7)
    at node.js:902:3

I went ahead and tried to do the same with one of the test files that get installed with node as such: 我继续尝试对通过node这样安装的测试文件之一执行相同的操作:

Minis-Mac:Projects newbnz$ node -p  /usr/local/lib/node_modules/npm/test/common.js

[eval]:1
/usr/local/lib/node_modules/npm/test/common.js
^
SyntaxError: Invalid flags supplied to RegExp constructor 'local'
    at new RegExp (<anonymous>)
    at [eval]:1:1
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:532:25)
    at startup (node.js:80:7)
    at node.js:902:3

I am running it on OS Mavericks. 我在OS Mavericks上运行它。

Disclosure: i am c/c++ dev and a newbie to JS and node.js. 披露:我是c / c ++开发人员,并且是JS和node.js的新手。

You are passing the -p flag, which according to node --help causes the following: 您正在传递-p标志,根据node --help会导致以下情况:

  -p, --print          evaluate script and print result

And then you pass your application's file path, ~/path/with/no/spaces/to/myFile.js , which is translated by your shell into /Users/maat/Projects/convert/application/models/mdAPI.js . 然后,您将应用程序的文件路径~/path/with/no/spaces/to/myFile.js传递给您,该~/path/with/no/spaces/to/myFile.js由您的Shell转换为/Users/maat/Projects/convert/application/models/mdAPI.js

Now since you used the -p flag, that "path" you thought you were telling node to use to launch your application is actually interpreted as raw javascript as though it was passwed to the eval function. 现在,由于使用了-p标志,因此您以为您要告诉节点用来启动应用程序的“路径”实际上被解释为原始javascript,就好像它已传递给eval函数一样。

And given the format of the path (starting with a / and with no enclosing single or double quotes around it), node interprets it as a javascript regular expression and then tries to evaluate it (with incorrect regex syntax) - thus causing the mysterious error in your console. 并给出路径的格式(以/开头,并且不包含单引号或双引号),节点将其解释为javascript正则表达式,然后尝试对其进行评估(使用不正确的regex语法)-从而导致神秘的错误在您的控制台中。

Long story short, remove the flag and you should get the behaviour that you want. 长话短说,删除标记,您应该得到想要的行为。

Since I am doing a port from PHP to Node, I missed an 'array' declaration at an obscure line at the beginning of the file. 由于我正在做从PHP到Node的移植,因此我在文件开头的晦涩之处错过了“数组”声明。 ie a syntactic error. 即语法错误。

After fixing the syntax error, I pushed my luck to see if i can use node -p as a means to check syntax only (posted somewhere in one of the questions on stack overflow), but it still didn't work. 修复语法错误后,我很幸运地发现我是否可以使用node -p作为仅检查语法的方法(在堆栈溢出问题之一中的某个位置发布),但仍然无法正常工作。

The way I found the error is that I opened a new js file, started copying stmt by stmt till I found it. 我发现错误的方式是我打开了一个新的js文件,开始逐个复制stmt,直到找到为止。

Thanks. 谢谢。

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

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