关于“令牌后期望的标识符”的JsHint抛出错误

时间:2022-12-01 23:35:02

I have created one small chatting app using node.js and socket.io. It is working fine for me, but my editor's (Eclipse) plug-in JsHint showing me one error in my code as follows.

我使用node.js和socket.io创建了一个小聊天应用程序。它对我来说很好,但是我的编辑器(Eclipse)插件JsHint在我的代码中向我显示了一个错误,如下所示。

io.sockets.in(room).emit(msgtype, data);

Error:

Syntax error on token ".", Identifier expected after this token

above code is running very well for me, but editor showing me error. I don't understand what is the problem, I have google for same error, but still not getting any solution. If someone show me how to write code in node.js, that is very helpful to me.

上面的代码对我运行得很好,但编辑器显示错误。我不明白是什么问题,我有谷歌相同的错误,但仍然没有得到任何解决方案。如果有人告诉我如何在node.js中编写代码,这对我很有帮助。

thanks,

2 个解决方案

#1


1  

Are you sure the problem is coming from JSHint? I had the exact same issue in Eclipse, I also had installed the JSHint plugin so (wrongly) assumed JSHint was warning about this. I tried es5:true etc. and nothing worked. Then I realized that JSHint was not showing this error. When you look at "Problems" tab you may see something like "Javascript Problem" after the errors, in which case it is the JSDT validation (only available as es3) is running rather than JSHint, which is what nodeclipse will default to as far as I understand, if installed. I had big problems disabling it, trying to "suspend validation" in Window-Preferences and whatnot. Finally, I edited the .project file as well and removed all "jsdt" containing lines from there like i.e.

你确定问题来自JSHint吗?我在Eclipse中遇到了完全相同的问题,我也安装了JSHint插件,因此(错误地)假设JSHint对此有所警告。我尝试了es5:true等等,没有任何效果。然后我意识到JSHint没有显示这个错误。当您查看“问题”选项卡时,您可能会在错误之后看到类似“Javascript问题”的内容,在这种情况下,JSDT验证(仅作为es3可用)运行而不是JSHint,这是nodeclipse默认为目前为止据我了解,如果安装。我有很大的问题禁用它,试图在Window-Preferences中“暂停验证”等等。最后,我编辑了.project文件并删除了所有包含行的“jsdt”,例如

org.eclipse.wst.jsdt.core.jsNature

After starting eclipse again, the error was gone, and I activated JSHint by selecting the files it should process and voila, I got "JSHint Problem" in Problems tab and it correctly did not warn me about the valid use of sockets.in any longer.

在再次启动eclipse之后,错误消失了,我通过选择它应该处理的文件来激活JSHint,瞧,我在Problems选项卡中得到了“JSHint Problem”,它正确地没有警告我有关sockets.in的有效使用。 。

Hope this helps anybody going through the same!

希望这有助于任何人经历同样的事情!

#2


0  

As noted above:

如上所述:

What version of JSHint are you using? Presumably the problem is that in is a reserved word and can only be used as a property identifier in that way in ES5. In recent versions of JSHint ES5 is assumed by default and that code should not issue a warning.

您使用的是什么版本的JSHint?据推测,问题是in是一个保留字,只能在ES5中以这种方式用作属性标识符。在最新版本的JSHint中,默认情况下假定ES5,并且该代码不应发出警告。

#1


1  

Are you sure the problem is coming from JSHint? I had the exact same issue in Eclipse, I also had installed the JSHint plugin so (wrongly) assumed JSHint was warning about this. I tried es5:true etc. and nothing worked. Then I realized that JSHint was not showing this error. When you look at "Problems" tab you may see something like "Javascript Problem" after the errors, in which case it is the JSDT validation (only available as es3) is running rather than JSHint, which is what nodeclipse will default to as far as I understand, if installed. I had big problems disabling it, trying to "suspend validation" in Window-Preferences and whatnot. Finally, I edited the .project file as well and removed all "jsdt" containing lines from there like i.e.

你确定问题来自JSHint吗?我在Eclipse中遇到了完全相同的问题,我也安装了JSHint插件,因此(错误地)假设JSHint对此有所警告。我尝试了es5:true等等,没有任何效果。然后我意识到JSHint没有显示这个错误。当您查看“问题”选项卡时,您可能会在错误之后看到类似“Javascript问题”的内容,在这种情况下,JSDT验证(仅作为es3可用)运行而不是JSHint,这是nodeclipse默认为目前为止据我了解,如果安装。我有很大的问题禁用它,试图在Window-Preferences中“暂停验证”等等。最后,我编辑了.project文件并删除了所有包含行的“jsdt”,例如

org.eclipse.wst.jsdt.core.jsNature

After starting eclipse again, the error was gone, and I activated JSHint by selecting the files it should process and voila, I got "JSHint Problem" in Problems tab and it correctly did not warn me about the valid use of sockets.in any longer.

在再次启动eclipse之后,错误消失了,我通过选择它应该处理的文件来激活JSHint,瞧,我在Problems选项卡中得到了“JSHint Problem”,它正确地没有警告我有关sockets.in的有效使用。 。

Hope this helps anybody going through the same!

希望这有助于任何人经历同样的事情!

#2


0  

As noted above:

如上所述:

What version of JSHint are you using? Presumably the problem is that in is a reserved word and can only be used as a property identifier in that way in ES5. In recent versions of JSHint ES5 is assumed by default and that code should not issue a warning.

您使用的是什么版本的JSHint?据推测,问题是in是一个保留字,只能在ES5中以这种方式用作属性标识符。在最新版本的JSHint中,默认情况下假定ES5,并且该代码不应发出警告。