Switching NodeJs application to debug mode from within it's process - debugging

I have a NodeJs module "some-module" that I want to have installed globally so it can be run directly from the command line without the node executable prefix. ie: $> some-module [args] I would like one of those arguments to be --debug. The reasoning for this is that I don't want to require users of this module to install it to their local directory just to run node --debug-brk node_modules/some-module/[path to entry point] [args].
The NodeJs documentation states in it's advanced usages section on debugging (http://nodemanual.org/latest/nodejs_ref_guide/debugging.node.js.html)
The V8 debugger can be enabled and accessed either by starting Node.js with the --debug command-line flag or by signaling an existing Node.js process with SIGUSR1.
I tried doing this with:
process.kill(process.pid, 'SIGUSR1');
Which produced the error:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Unknown signal: SIGUSR1
at EventEmitter.kill (node.js:366:17)
at Object.<anonymous> (c:\dev\some-module\app.js:94:17)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)
What do I need to do to get the running process switched to debug mode?
Also, I would like to debug the given application with node-inspector.

I'm not quite sure if I understood your question, but...
You can probably install an app globally and have it stop in a breakpoint using npm. In package.json put:
...
"scripts": {"start": "node --debug-brk some-module.js"},
"bin" : { "some-module" : "./some-module.js" },
...
Running npm start -g some-module will break at first line.
You can then use node-inspector for debugging.
About the part with stopping from within the code, node has a build in debugger (which is quite rudimentary), but it allows this functionality.
If you include somewhere in the code:
debugger;
and run:
node debug some-module.js
it will stop there in the debugger (note: this is not the same as node-inspector, i don't know if this can be achieved with node-inspector).
Don't really understand the reason why you're doing this, but hope this helps.

Related

Error: Cannot find module code: 'MODULE_NOT_FOUND', (metaplex)

im heaving trouble uploading my NFT to the devnet in solana using metaplex cli
im following a tutorial on buildspace: https://buildspace.so/p/ship-solana-nft-collection/
(should be noted! im using WSL)
i followed as instructed and when i needed to upload my nfts throught metaplex i ran the command:
ts-node ~/metaplex/js/packages/cli/src/candy-machine-v2-cli.ts upload -e devnet -k ~/.config/solana/devnet.json -cp config.json ./assets
and then this eror pops up:
==========================================================================================
wallet public key: HAMgtaBZBZM8U1AJ5BGMDEcmoLqCzqL7mu9BU2kgrzCN
(node:12137) ExperimentalWarning: buffer.Blob is an experimental feature. This feature could change at any time
(Use node --trace-warnings ... to show where the warning was created)
(node:12137) UnhandledPromiseRejectionWarning: Error: Non-base58 character
at Object.decode (/home/deathsn1per/metaplex/js/node_modules/base-x/src/index.js:111:11)
at new PublicKey (/home/deathsn1per/metaplex/js/node_modules/#solana/web3.js/src/publickey.ts:56:30)
at getCandyMachineV2Config (/home/deathsn1per/metaplex/js/packages/cli/src/helpers/various.ts:164:9)
at Command. (/home/deathsn1per/metaplex/js/packages/cli/src/candy-machine-v2-cli.ts:157:38)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(node:12137) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:12137) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
=========================================================================================
i proceeded to inspect where the warning came from using:
node --trace-warnings ...
and it showed me this:
=======================================================================================
Error: Cannot find module '/home/deathsn1per/Projects/solanaXreact/nft-drop-starter-project/...'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
=========================================================================================
i thought maybe something wrong with the way installed metaplex, so i deleted every thing and re installed but nothing..
i installed metaplex files in home/deathsn1per/metaplex...
from what little i understand this is a problem with the modules, something went wrong with the installetion but i cant figure out what is it...
so im kinda lost as where to look even. or what to do to fix it, any help would be very nice!
i hope i provided with enough info (if needed more info pls dont kill just tell me what you need to know ;) )
The tutorial is way outdated. The tool that you are trying to use is deprecated and not supported anymore.
You should be using sugar instead which is a cli that is way faster and more reliable than the old js cli.
You can find a tutorial on the official docs here:
https://docs.metaplex.com/developer-tools/sugar/tutorials/my-first-candy-machine

Reaction Commerce deployment to Heroku failing, boot_proxy.js not generated

I was trying to set up a running instance running on Heroku by following these instructions. All goes well but after the build is finished, an error occurs and the app crashed.
Error: Cannot find module /app/.meteor/heroku_build/bin/boot_proxy.js
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
Process exited with status 1
This is the content of the Procfile.
web: .meteor/heroku_build/bin/node .meteor/heroku_build/bin/boot_proxy.js .meteor/heroku_build/bin/node .meteor/heroku_build/app/main.js
I used heroku bash to explore the app and saw that The file boot_proxy.js is not being generated. Does anyone know a fix to this? Already filed a bug on git repo.
As it can be found in this forked repo the missing boot_proxy.js comes from a overdue startup of reaction:
Sometimes reaction takes too much time to start and Heroku thinks that there's a problem with your app. To sidestep this we have a simple proxy that answers every request until it's ready.
https://github.com/Zanobo/reaction-buildpack#boot-proxy
So in order to fix the issue, you should use this fork at the buildpack step:
heroku buildpacks:set https://github.com/Zanobo/reaction-buildpack.git
and add this environment variable in Heroku:
USE_BOOT_PROXY=1

Cannot run in production mode

I have a donejs application and its running ok in development mode donejs develop, but when I run it in production mode:
donejs build
donejs deploy (to firebase)
NODE_ENV=production donejs start
it will not start and show an error (see CODE A)
This file: file:my-app/dist/bundles/my-app/index.js:704 corresponds to JQuery 3.x and its not a dependency of the project itself but a dependency of can-connect-feathers (https://github.com/canjs/can-connect-feathers). In fact in index.js there is also included JQuery 2.x what makes me think there might be some sort of incompatibility among them.
I already tried changing the project's dependency to JQuery 3.x but didn't help. Actually it will make even donejs develop fail (see CODE B).
I also tried the following:
cd my-app/node_modules/steal
npm install
but didn't help, another error appears and finally tried cd my-app/node_modules/can && npm install but that end up in multiple errors.
I'm using:
donejs#0.9.2
node#4.6.2
npm#2.15.11
can-connect-feathers#1.2.1
CODE A
NODE_ENV=production donejs start
my-app#0.0.0 start my-app
done-serve --proxy http://localhost:3030 --port 8080
done-serve starting on http://localhost:8080
Potentially unhandled rejection [5] TypeError: Error loading "package.json!npm" at file:my-app/package.json
Error loading "bundles/my-app/index" at file:my-app/dist/bundles/my-app/index.js
Error evaluating file:my-app/dist/bundles/my-app/index.js
Cannot read property 'createElement' of undefined
at i (file:my-app/dist/bundles/my-app/index.js:704:20)
at file:my-app/dist/bundles/my-app/index.js:1039:2881
at file:my-app/dist/bundles/my-app/index.js:1039:3580
at file:my-app/dist/bundles/my-app/index.js:268:21
at file:my-app/dist/bundles/my-app/index.js:268:27
at Object.exports.runInThisContext (vm.js:54:17)
at doEval (my-app/node_modules/steal/node_modules/steal-systemjs/dist/system.src.js:2059:10)
at __eval (my-app/node_modules/steal/node_modules/steal-systemjs/dist/system.src.js:1976:7)
at Loader.exec [as __exec] (my-app/node_modules/steal/node_modules/steal-systemjs/dist/system.src.js:339:5)
at Loader.loader.instantiate (my-app/node_modules/steal/node_modules/steal-systemjs/dist/system.src.js:1517:16)
CODE B
donejs develop
my-app#0.0.0 develop my-app
done-serve --develop --proxy http://localhost:3030 --port 8080
done-serve starting on http://localhost:8080
Potentially unhandled rejection [8] Error: Error loading "my-app#0.0.0#index.stache!done-autorender#0.8.0#autorender" at <unknown>
Error loading "can#2.3.27#util/jquery/jquery" at file:my-app/node_modules/can/util/jquery/jquery.js
Error loading "can#2.3.27#util/jquery/jquery" from "done-autorender#0.8.0#autorender" at file:my-app/node_modules/done-autorender/src/autorender.js
Did not find ./node_modules/can/node_modules/jquery/package.json
at FetchTask.utils.extend.next (file:my-app/node_modules/steal/ext/npm-crawl.js:532:11)
at file:my-app/node_modules/steal/ext/npm-crawl.js:556:33
at tryCatchReject (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:1183:30)
at runContinuation1 (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:1142:4)
at Fulfilled.when (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:930:4)
at Pending.run (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:821:13)
at Scheduler._drain (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:97:19)
at Scheduler.drain (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:62:9)
at nextTickCallbackWith0Args (node.js:436:9)
at process._tickCallback (node.js:365:13)
Potentially unhandled rejection [16] Error: Error loading "can#2.3.27#util/jquery/jquery" at file:my-app/node_modules/can/util/jquery/jquery.js
Error loading "can#2.3.27#util/jquery/jquery" from "my-app#0.0.0#index.stache!done-autorender#0.8.0#autorender" at file:my-app/src/index.stache
Did not find ./node_modules/can/node_modules/jquery/package.json
at FetchTask.utils.extend.next (file:my-app/node_modules/steal/ext/npm-crawl.js:532:11)
at file:my-app/node_modules/steal/ext/npm-crawl.js:556:33
at tryCatchReject (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:1183:30)
at runContinuation1 (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:1142:4)
at Fulfilled.when (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:930:4)
at Pending.run (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:821:13)
at Scheduler._drain (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:97:19)
at Scheduler.drain (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:62:9)
at nextTickCallbackWith0Args (node.js:436:9)
at process._tickCallback (node.js:365:13)
If the double jQuery installation is the issue, it should be resolved by version 2.0.0, which is exactly the same as the 1.0 version, but requires that you pass in a jQuery package as the jquery option. So, in addition to whatever else you had in your can-connect-feathers config, you'll need to provide the jquery option:
import $ from 'jquery'
import Feathers from 'can-connect-feathers';
new Feathers({
jquery: $
});

HowTo launch node --debug grunt server on Windows?

Running Windows 8.1 and my environment is working great except I cannot start node in --debug so that node-inspector has something to connect to.
I have a Gruntfile setup with grunt-concurrent that lets me open, grunt-devtools, node-inspector then watch just fine but I can't figure out a workable syntax for getting that running with node in debug. Following is what I'd expect to work but also the error I get when I try. Notice that there is a message indicating that the debug server is listening, but something falls apart from there and fails so it does me no good.
C:\PROJECTS\bManWebService_Hapi>node --debug C:\Users\rainabba\AppData\Roaming\npm\grunt server
debugger listening on port 5858
C:\Users\rainabba\AppData\Roaming\npm\grunt:2
basedir=`dirname "$0"`
^
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:437:25)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
It looks like the file C:\Users\rainabba\AppData\Roaming\npm\grunt is not a JS file but a bash shell script. Look for grunt.cmd in the same folder if you need Windows-compatible version.
And event if you find grunt.cmd - starting it as node grunt.cmd is not a proper way. Most likely the grunt.cmd will start the node so you need to somehow pass the --debug argument to the node, called by the grunt.cmd or just run node exactly as grunt.cmd runs it.
tl; tr;
node --debug-brk c:\Users\rainabba\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt taskname
You have to use this executable
c:\Users\rainabba\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt
instead of this
c:\Users\rainabba\AppData\Roaming\npm\grunt server

Docpad Run, errors and warnings

Node.js and Docpad are installed via: http://docpad.org/docs/install
npm install -fg docpad#6.21
docpad run via: http://docpad.org/docs/start
mkdir my-website
cd my-website
docpad run
Selected 6.) Hogan (Skeleteon)
and got this:
info: Installed the skeleton succesfully
info: DocPad listening to http://localhost:9778/ on directory c:\Users\DM\My Doc
uments\MDM\Web Projects\Client Projects\Web-Mart\Development\Website\out
info: LiveReload listening to new socket on channel /docpad-livereload with log
level 1
info: Generating...
warning:
Rendering the extension "eco" to "html" on "index.html.eco" didn't do anything
.
Explanation here: http://docpad.org/extension-not-rendering
warning:
Rendering the extension "eco" to "html" on "footer.html.eco" didn't do anythin
g.
Explanation here: http://docpad.org/extension-not-rendering
warning: Something went wrong while rendering: c:\Users\DM\My Documents\MDM\Web
Projects\Client Projects\Web-Mart\Development\Website\src\layouts\default.html.e
co
warning: Something went wrong while rendering: c:\Users\DM\My Documents\MDM\Web
Projects\Client Projects\Web-Mart\Development\Website\src\layouts\primary.html.e
co
warning: Something went wrong while rendering: c:\Users\DM\My Documents\MDM\Web
Projects\Client Projects\Web-Mart\Development\Website\src\documents\index.html.e
co
error: Something went wrong with the action
error: An error occured:
TypeError: Object #<Object> has no method 'getFileUrl'
at Object.eval (eval at <anonymous> (C:\Users\DM\Documents\MDM\Web Projects\
Client Projects\Web-Mart\Development\Website\node_modules\docpad-plugin-eco\node
_modules\eco\lib\compiler.js:19:12))
at Object.eval (eval at <anonymous> (C:\Users\DM\Documents\MDM\Web Projects\
Client Projects\Web-Mart\Development\Website\node_modules\docpad-plugin-eco\node
_modules\eco\lib\compiler.js:19:12))
at eval (eval at <anonymous> (C:\Users\DM\Documents\MDM\Web Projects\Client
Projects\Web-Mart\Development\Website\node_modules\docpad-plugin-eco\node_module
s\eco\lib\compiler.js:19:12))
at Function.eco.render (C:\Users\DM\Documents\MDM\Web Projects\Client Projec
ts\Web-Mart\Development\Website\node_modules\docpad-plugin-eco\node_modules\eco\
lib\index.js:26:25)
at EcoPlugin.module.exports.EcoPlugin.render (C:\Users\DM\Documents\MDM\Web
Projects\Client Projects\Web-Mart\Development\Website\node_modules\docpad-plugin
-eco\out\eco.plugin.js:23:37)
at Object.balUtilFlow.fireWithOptionalCallback (c:\Users\DM\AppData\Roaming\
npm\node_modules\docpad\node_modules\bal-util\out\lib\flow.js:39:27)
at BasePlugin.bindEvents (c:\Users\DM\AppData\Roaming\npm\node_modules\docpa
d\out\lib\plugin.js:57:26)
at Object.balUtilFlow.fireWithOptionalCallback (c:\Users\DM\AppData\Roaming\
npm\node_modules\docpad\node_modules\bal-util\out\lib\flow.js:32:27)
at Object.EventEmitterEnhanced.emitSync (c:\Users\DM\AppData\Roaming\npm\nod
e_modules\docpad\node_modules\bal-util\out\lib\events.js:49:30)
at Object.balUtilFlow.fireWithOptionalCallback (c:\Users\DM\AppData\Roaming\
npm\node_modules\docpad\node_modules\bal-util\out\lib\flow.js:32:27)
I've never gotten past these warnings and errors and it'd be very nice to be able to use docpad so I am grateful for any ideas on how to rid my seeming Docpad curse. Thank you.
Yeah the skeleton is broken, I don't know who's maintaining it. Like I mentioned in IRC, for others that might read/need I'll post here too...
You can use a empty folder and do this from the shell or you can just use the empty template:
cd $(mktemp -d) && npm i docpad docpad-plugin-hogan && \
mkdir -p src/{documents,files,layouts} && \
curl https://raw.github.com/docpad/docpad-plugin-hogan/master/test/src/documents/hogan.html.hogan \
> src/documents/index.html.hogan && docpad run
Should work to demonstrate hogan plugin and docpad itself work fine.
Personally I always start with a package.json but thats just how I like to do it, define plugins as you need them in there but you can all just do it manually as well... Or use the basic HTML5 boilerplate plugin and then add docpad-plugin-hogan etc.
Or wait until it get fixed if you must have that skeleton...

Resources