It's all about the answers!

Ask a question

[JazzHub -> Code] 'required' is not defined

Takehiko Amano (1.3k3741) | asked May 30 '13, 3:16 a.m.
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 ?

Accepted answer

permanent link
Lauren Hayward Schaefer (3.3k11727) | answered May 30 '13, 7:23 a.m.
edited May 30 '13, 7:25 a.m.
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.
Takehiko Amano selected this answer as the correct answer

Takehiko Amano commented May 30 '13, 10:17 p.m.

Thanks. The error went away.

2 other answers

permanent link
McQ Wilson (613) | answered Jun 01 '13, 12:33 p.m.
What you are seeing is output from the JSLint tool (, 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*/

permanent link
Iwan Winoto (323) | answered Jun 02 '13, 9:27 p.m.
I have the same problem with my code in JazzHub Orion.

If I parse my code at the JSLint site ( 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 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.

McQ Wilson commented Jun 03 '13, 3:43 p.m.

Thanks, Iwan. I'm not sure why options that worked at wouldn't work here, other than perhaps we're running a different version of JSLint. I'll enter a bug report to capture the issue, and check it out when I get back from Innovate. 

McQ Wilson commented Jun 03 '13, 3:47 p.m.

Here's the bug report if you want to track it:

Your answer

Register or to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.