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 268933 - Not possible to run/debug file after enable Node.js support
Summary: Not possible to run/debug file after enable Node.js support
Status: RESOLVED INVALID
Alias: None
Product: javascript
Classification: Unclassified
Component: Node.js (show other bugs)
Version: 8.2
Hardware: All All
: P2 normal (vote)
Assignee: Tomas Mysik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-10 16:18 UTC by Christian Lenz
Modified: 2016-11-14 10:36 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Sample project. (89.66 KB, application/octet-stream)
2016-11-11 21:53 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-11-10 16:18:10 UTC
I have a HTML5/JavaScript project and I can right click in a JS file and have 2 Options: Run file or Debug file. I go to the project properties and enabled Nodejs support, resolved problems, so I downloaded the sources and after this, the 2 options inside the context menu inside a file, are gone. This is not what I expected. There should be no difference.


Regards

Chris
Comment 1 Tomas Mysik 2016-11-11 07:14:11 UTC
I have a suspicion, but please, attach a sample project and reopen this issue.
BTW what exactly happens if you invoke the Run action (before you enabled the Node.js support)?

Thanks.
Comment 2 Christian Lenz 2016-11-11 21:46:28 UTC
At work I got this error: 
debug:
shopSettingsAPI.spec.js:7 ReferenceError: "describe" is not defined
C:\Users\chrl\AppData\Local\NetBeans\Cache\8.2\executor-snippets\debug.xml:83: Java returned: 102
BUILD FAILED (total time: 2 seconds)

it is a unit test file for karma using jasmine. I got the same when I try to run it which is ok because describe is not defined ^^.

At home, I have an other file, normal js file inside a HTML5/JS project and I got this message:

run:
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
	at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
	at java.lang.Thread.run(Thread.java:745)
Caused by: slider.js:10 ReferenceError: "document" is not defined
	at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
	at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319)
	at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291)
	at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:278)
	at jdk.nashorn.internal.runtime.ScriptObject.noSuchProperty(ScriptObject.java:2357)
	at jdk.nashorn.internal.runtime.ScriptObject.findGetMethod(ScriptObject.java:1952)
	at jdk.nashorn.internal.objects.Global.findGetMethod(Global.java:2149)
	at jdk.nashorn.internal.runtime.ScriptObject.lookup(ScriptObject.java:1820)
	at jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:104)
	at jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:98)
	at jdk.internal.dynalink.support.CompositeTypeBasedGuardingDynamicLinker.getGuardedInvocation(CompositeTypeBasedGuardingDynamicLinker.java:176)
	at jdk.internal.dynalink.support.CompositeGuardingDynamicLinker.getGuardedInvocation(CompositeGuardingDynamicLinker.java:124)
	at jdk.internal.dynalink.support.LinkerServicesImpl.getGuardedInvocation(LinkerServicesImpl.java:154)
	at jdk.internal.dynalink.DynamicLinker.relink(DynamicLinker.java:253)
	at jdk.nashorn.internal.scripts.Script$Recompilation$5$13$slider.L:1(slider.js:10)
	at jdk.nashorn.internal.scripts.Script$4$slider.:program(slider.js:1)
	at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637)
	at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
	at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
	at jdk.nashorn.internal.runtime.Context.evaluateSource(Context.java:1224)
	at jdk.nashorn.internal.runtime.Context.load(Context.java:837)
	at jdk.nashorn.internal.objects.Global.load(Global.java:1530)
	at jdk.nashorn.internal.scripts.Script$Recompilation$3$875A$\=fx\!bootstrap.start(fx:bootstrap.js:47)
	at javafx.application.Application$$NashornJavaAdapter.start(Unknown Source)
	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
	at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
	at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
	... 1 more
C:\Users\Chrizzly\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)


Maybe this happens in case of this bug: https://netbeans.org/bugzilla/show_bug.cgi?id=258828

maybe you can take the sample file from there too. I will test it.
Comment 3 Christian Lenz 2016-11-11 21:53:28 UTC
Created attachment 162880 [details]
Sample project.

Same happens here when I run a js file. Same exception. But this is not the case, the case was that those options like run file and debug file are not available. Unfortunately at home they are available ^^. Hm I will check it at work.
Comment 4 Tomas Mysik 2016-11-14 07:12:02 UTC
No issue here, it works as designed, sorry. Let me explain - if you have HTML5 project without Node.js support, then Run and Debug actions are added by Java support (the nashorn, see your stacktrace). But once you add Node.js support for the given HTML5 project, only Source Files can be run/debugged as single JS files (via Node.js, of course); in other words, it does not make much sense to run/debug any JS file which is underneath Site Root folder (since all these files are supposed to be opened by browser).

Thanks.
Comment 5 Christian Lenz 2016-11-14 09:53:30 UTC
Ok I understand your point.

The problem is often HTML5/JavaScript projects don't have only client side files. They have server side npm scripts to do stuff or grunt or gulp or tests. Each of those files should be called from Run file/debug file and should run with the node executable. The problem what I have is that I don't know what are the differences from enabling node.js in html5 projects. If there is no difference, except run scripts with node, then I can enable Node.jS for all my HTML5/JavaScript projects, where I can npm scripts, where node is needed, right?

Maybe we can close this ticket: https://netbeans.org/bugzilla/show_bug.cgi?id=258828 in case of your explanation too.
Comment 6 Tomas Mysik 2016-11-14 10:16:28 UTC
(In reply to ChrisLE from comment #5)
> They have server side npm scripts to do stuff or grunt or gulp or
> tests.

NB has support for npm, Grunt and Gulp - in which cases they cannot be used? Please, describe your scenario.

> Each of those files should be called from Run file/debug file and
> should run with the node executable.

Why? I would expect that they are run by npm/Grunt/Gulp? If not, why? What is the use case, please?

> The problem what I have is that I don't
> know what are the differences from enabling node.js in html5 projects. If
> there is no difference, except run scripts with node, then I can enable
> Node.jS for all my HTML5/JavaScript projects, where I can npm scripts, where
> node is needed, right?

The difference is simple - HTML5 project without Node.js support represents client-side application - all its files are supposed to be run via browser (the project has only Site Root). HTML5 project with Node.js support has Source Files (the server side, to be run via Node.js) and _can_ have also the client-side part (as described earlier).

> Maybe we can close this ticket:
> https://netbeans.org/bugzilla/show_bug.cgi?id=258828 in case of your
> explanation too.

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

Thanks.
Comment 7 Christian Lenz 2016-11-14 10:36:44 UTC
Sometimes you have some helper JS files. So because that NodeJS is supported as a scripting language on the server or on the PC, each script should be runable via node like node > myScript. Like in python or ruby or whereever. So no npm run needed or Grunt or Gulp. Please go out from the thing that npm, gulp and grunt is everything you have. Sure some people using scaffolding templates from yeoman or a new created one so it really should be possible to run scripts via node like whatever, do stuff. Like real node projects, there is is possible too.

So as I said, if there is no difference between HTML5/JS with or w/o enabling NodeJS support, I can enable NodeJS for my project, because I have node scripts which are not running with npm, grunt or gulp, only with node. Of course it is possible to create a script property inside the package json for each script that I have but no I don't want it. When I'm inside this file, I will run this file.

The thing which run file and browser will open it, inside the site root the JS files or CSS files will open in the browser, which doesn't make sense, why? Why should my scripts or css files opened in a browser? I can't do anything with them only see the source, and this is what I already have in my IDE.


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


Yes exactly what you said, makes more sense. Thx