[JazzHub -> Code] 'required' is not defined
I have edited some codes ( node.js) and uploaded into source code repository (RTC SCM). Now, I tried to edit the code. However, I get error messages in the editor pane.
I checked the project "spirit | Orionnode". In this case, this kind of errors seems not happening.
The code is very simple just like this.
var foo = require('module');
Is there any required setting for .js (JavaScript) editor ?
I checked the project "spirit | Orionnode". In this case, this kind of errors seems not happening.
The code is very simple just like this.
var foo = require('module');
Is there any required setting for .js (JavaScript) editor ?
Accepted answer
Hi,
I poked around a bit at the code that wasn't throwing errors in "spriit | Orionnode." It seems that if you add the line
the warnings go away. I'm not sure what the significance of that line is. I'll open a work item and let you know what I hear back.
I poked around a bit at the code that wasn't throwing errors in "spriit | Orionnode." It seems that if you add the line
/*global __dirname console exports process require*/
the warnings go away. I'm not sure what the significance of that line is. I'll open a work item and let you know what I hear back.
2 other answers
What you are seeing is output from the JSLint tool (http://www.jslint.com), which is integrated with the JazzHub development tools. JSLint scans the entire file, but does not look at other files, so things like the "require" function (which is defined elsewhere in the node.js library) are not visible to JSLint.
The pattern /*global ...*/ is a hint for JSLint that the indicated items are defined somewhere outside the current file, so to fix "'require' is not defined", you would need just:
/*global require*/
I have the same problem with my code in JazzHub Orion.
If I parse my code at the JSLint site (http://www.jslint.com/) it also complains. However at the bottom of the JSLint parser, there are options to let the parser know the code is Node as well as setting other options (variables starting with '_', turn off warnings about unused parameters, etc).
Another way of setting those options is with a comment at the top of the code:
/*jslint node: true, nomen: true, unparam: true, sloppy: true */
This comment tells JSLint that its node.js code (so it accepts keywords like 'require', 'process', etc).
With this directive, the validator at jslint.com clears my code. However, JazzHub Orion still complains about my code even with this directive.
While I can clear validation errors with /*global ...*/ directive, I'd rather not have to fill it with all the node.js core objects. The validator should recognise node.js code (either be cause I have a node directive, or from the structure of the project - i.e. inclusion of a package.json file) and not complain about node.js core objects.
So I think there is still something wrong with the JSLint in JazzHub Orion.