This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 258828 - Please add feature to run a js file with run file in a HTML5 project without node support.
Summary: Please add feature to run a js file with run file in a HTML5 project without ...
Status: NEW
Alias: None
Product: javascript
Classification: Unclassified
Component: Node.js (show other bugs)
Version: 8.2
Hardware: All All
: P3 normal (vote)
Assignee: Tomas Mysik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-14 12:12 UTC by Christian Lenz
Modified: 2016-11-14 10:37 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Gulp test with testScript (89.66 KB, application/octet-stream)
2016-04-14 14:36 UTC, Christian Lenz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Lenz 2016-04-14 12:12:17 UTC
When I have a HTML5 client project, where I have to use grunt or gulp, often you have sume node scripts, which you want to test. This is what I tried to run a script with "Run file" and wondered, why I got a message like:

run:
nodeScriptTest.js:1 ReferenceError: "require" is not defined
C:\Users\chrl\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 102
BUILD FAILED (total time: 0 seconds)


This is the smallest example, where this happens:

var fs = require('fs');

console.log('Test von node.');

The problem is, that I can run the file inside a HTML5 client project, but they will not be executed with node. I don't know which applicaton tries to execute the script. I enabled the node support for this project and everything was fine.

At the first view it is very confusing, to have the functionality to run file (Ctl + u) for JS files in a HTML5 client project, but to not know, that you have to enable the node support for this.


It would be handy, if I want to run a js file doesn't matter where I am, to call node "myFile.js". It shouldn't care whether node.js support is enabled or not.


Regards

Chris
Comment 1 Tomas Mysik 2016-04-14 13:00:00 UTC
Could you please attach a sample project?

BTW I would guess that your JS file was run using JDK (see Tools > Options > Java > Nashorn).

Thanks.
Comment 2 Christian Lenz 2016-04-14 14:36:45 UTC
Created attachment 159268 [details]
Gulp test with testScript

So testScript.js is my little node script what I should run with "Run File", what is not possible, because the gulp-test-nb project is a HTML5 project with disabled node.js support. As you can see in the gulpfile, I wanted to call the test module, doesn't matter what is in. So this is a real world example, where you have helpers (testScripts.js) which you want to call inside gulp for example, but it is a normal HTML5 Client Side Project.

The problem is not, that I don't want to enable node.js, if this is normal behaviour and has no other side effect, the problem  is, that when I want to execute the file with ctrl + u, nothing happens or with the context menu, Nashorn, as you said, will execute it. To execute the file correct, I have to enable node.js.
Comment 3 Tomas Mysik 2016-11-14 10:18:00 UTC
As discussed in issue #268933:

Perhaps it would be nice if any JS file _outside_ the Site Root folder could have Run/Debug action which would invoke Node.js (if Node.js is enabled for the given project, of course).

This would work for all kind of "helper" scripts (for building, deplyment etc.).

Thanks.
Comment 4 Tomas Mysik 2016-11-14 10:19:12 UTC
One more note: the current implementation adds Run/Debug action to JS files that are underneath Source Files folder only.
Comment 5 Christian Lenz 2016-11-14 10:37:35 UTC
Thx for the comment. Yes this will open the files inside the browser, which doesn't make sense to me.