Closed Jusys closed 6 years ago
Just use terminal in VSC and write node debug.js
or node release .js
:-)
I will try - but will all VS Code debug features work? Like breakpoints/variable resolving/intellisense? I'll try.
Ok I tried, and I can attach to totaljs process, but breakpoints still not work - I will try more, when I'll have time.
Hi, did you get something like this?
Debugger listening on ws://127.0.0.1:35944/1d1a0c47-47b1-434d-9d63-52aeca32fd30
Debugger attached.
Starting inspector on 127.0.0.1:35944 failed: address already in use
Waiting for the debugger to disconnect...
Are you using win, lin or mac?
I would recommend you to use new beta yarn add total.js@beta
. I'm using following code to start dev server
require('total.js');
F.http('debug', { port: 3070, ip: '127.0.0.1', inspector: 9229 });
And I attached simple project for you. First install dependencies, open debug.js
and hit F5
total-debug.zip
Hmm, when I change debug.js to this:
require('total.js/debug')({ port: 3070, ip: '127.0.0.1', inspector: 9229 });
it also works and it reloads server when code changes.
So after a few tries I ended with this:
if using VisualStudio Code - and debugging release.js (just hit F5 and have proper launch.json configuration) with following code:
require('total.js').http('release', options);
or require('total.js').http('debug', options);
debugging works fine, but server does not restart automatically when there is a change in source files.
If I use debug.js with:
require('total.js/debug')(options);
then when hitting F5 (having the same launch.json configuration as for release.js) - process starts, outputs -------------------------> DEBUG PID: 10072 (v2.9.4)
and immediately ends.
If I use @michalCapo code (from total-debug.zip) then process starts and hangs while displaying -------------------------> DEBUG PID: 10072 (v2.9.4)
(http://127.0.0.1 is not accessible - web server does not start).
when I try to run node debug.js
- server starts, but then then only way to debug is to attach VSCode debugger to process id and breakpoints don't work - they're grayed out (automatic code reloading works).
P.S. I use following launch.json setting for @michalCapo example:
{
"type": "node",
"request": "launch",
"name": "total-debug",
"program": "${workspaceFolder}\\websites\\total-debug\\debug.js"
}
P.P.S. I use following directory structure in my test totaljs project: \test-totaljs \test-totaljs\node_modules \test-totaljs\websites\total-debug \test-totaljs\websites\website1 \test-totaljs\websites\cms \test-totaljs\websites\ecommerce
And how your options are defined? What kind of OS do you use? Which version of total.js are you using?
maybe it would be faster to comunicate via https://messenger.totaljs.com/
I think I'll stick with restarting server manually for now, but in case you're interested here are my options you asked:
Windows 7 32bit / Windows 10 64 bit Total.js 2.9.4 Node.js 10.0.0
Options (my project):
const options = {};
options.inspector = 9229;
options.port = 81;
require('total.js/debug')(options);
Options (@michalCapo example):
require('total.js/debug')({ port: 3070, ip: '127.0.0.1', inspector: 9229 });
P.S. if I'll continue to learn and use total.js - I'll rise this issue once again (if it will be not solved by that time and if I fail to solve it myself).
@Jusys total.js/debug
is a special mode which can make some problems because it opens another thread with app. Create a new start script called e.g.:
app.js:
var options = {};
require('total.js').http('debug', options);
And just update your VSC meta file. This script is something similar like express.js
start script but this script won't monitor changes in your app and you need to restart app manually when you perform some change.
@petersirka Ok, I'll do that. You may close this issue.
You need to use version 3.x, which is now in beta. 'npm install total.js@beta' Then it will work.
i confirm @petersirka method works, on latest beta as @michalCapo pointed out.
FYI, if you add "main": "debug.js"
to your package.json
you can debug directly without specific VS launch config files.
Is it possible to debug the view engine related code in total.js example apps? In example the js code in "themes/default/views"? How to debug this? I've tried to pass the sourcemaps but it passes only the upper level js code, not the one from views.
https://github.com/totaljs/eshop/blob/master/themes/default/views/eshop/checkout.html
No, this is not possible. You can use only: https://docs.totaljs.com/latest/en.html#api~FrameworkViews~%40%7Bconsole.log
https://docs.totaljs.com/latest/en.html#pages~Debugging~(how-to-run-total-js-debug-)
yay, cool info, thanks bro! I'm sure it works in Sublime, BUT can you tell me how VisualStudioCode must be configured to run debug.js? If I run with following config:
{
"type": "node",
"request": "launch",
"name": "total-blabla",
"program": "${workspaceFolder}\\debug.js"
}
all I get is:
-------------------------> DEBUG PID: 7316 (v2.9.4) debug.js:323
and then process stops and program exits.