Debugging node apps using node-inspector is pretty simple if you're scripting using JavaScript or compiled Coffee (coffee -c -m script.coffee).
However, when using the coffeescript require handler:
require('coffee-script/register');
require('lib/component.coffee');
in a script I'm trying to debug using node-debug, I get:
(function (exports, require, module, __filename, __dirname) { #
^
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
...
right as I require the file.
Is what I'm trying to do possible? I have several CoffeeScript files that I would much rather not have to compile each time I want to test.
Yes, definitely. I use it all the time, the command line looks like these:
node-inspector & coffee --nodejs --debug-brk ./scripts/mongoEtl.coffee
node-inspector & mocha --compilers coffee:coffee-script ./test/dataLayer-test.coffee --ui bdd --debug-brk
node-inspector --web-port=5870 & mocha --compilers coffee:coffee-script/register ./test/dataLayer-test.coffee --ui bdd --debug-brk=5880 -g 'my test name here'
I just checked the last line, it's working and has coffeescript requires in it. However when I'm debugging I'm actually seeing javascript, not coffee. I don't know if it's possible to run and debug coffeescript with node-inspector (edit: yes, it is, use of source maps is required but that is out of scope for this answer). I'm not convinced that has value -- I think it's good to be able to read javascript well, so I haven't looked into it.
I think your issue might be in the compilation, have you tried compiling the file that's being required?
Related
I'm looking at a file in WebStorm that contains Jest tests. I can run Jest via a run configuration and it works fine.
However, I can't right-click on a test in the editor and run it, nor do I get any gutter icons that would let me do so. I can right-click on a describe or it block and I have the option to run or debug, but it's trying to run/debug the file, not run the test:
(function (exports, require, module, __filename, __dirname) { import React from "react";
^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
Process finished with exit code 1
This is a new installation on a new M1 MacBook Pro, but it's got my settings synced with my other machines, so I don't see any reason why this wouldn't work like all my other WebStorm installations. (And it's not just this file, it's any test file anywhere.)
The problem solved itself when I removed babel-jest from our dependencies and added jest, which hadn't previously been there even though the tests would run, including using the "Run tests" run config.
As #lena suggested, the problem appeared to be not having Jest in the package file.
Being fairly new to node and ts-node, I'm struggling to figure out how to run tests from this open source project -- https://github.com/pocesar/node-stratum (which are .ts files). I installed both "typescript" and "ts-node" ...
localhost:node-stratum satishp$ npm install -g typescript
/usr/local/bin/tsc -> /usr/local/lib/node_modules/typescript/bin/tsc
/usr/local/bin/tsserver -> /usr/local/lib/node_modules/typescript/bin/tsserver
+ typescript#2.7.2
added 1 package in 2.974s
localhost:node-stratum satishp$ npm install -g ts-node
/usr/local/bin/ts-node -> /usr/local/lib/node_modules/ts-node/dist/bin.js
+ ts-node#5.0.1
added 17 packages in 1.596s
but when I go to run the tests, located in the "test/tests.ts" directory, I get teh following error
localhost:node-stratum satishp$ ts-node test/tests.ts
Error: Cannot find module '../lib'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/satishp/Documents/workspace/node-stratum/test/tests.ts:3:1)
at Module._compile (module.js:660:30)
at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:400:23)
at Module._extensions..js (module.js:671:10)
at Object.require.extensions.(anonymous function) [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:403:12)
at Module.load (module.js:573:32)
Is there something more I need to do to get the test file to run properly?
After a small bit of research, here's what it looks like you should do:
Clone the repo (I assume you've already done this, only here for completeness' sake)
Run npm install in the cloned folder. This way you'll have all of the project's specific package versions.
Run tsc to compile the source files into the lib folder. Ignore the type errors; the code should still compile.
Run tsc -p tests.json to compile the test files, which uses the tests.json file as a tsconfig. Again, ignore the type errors.
Run mocha test to actually run the tests on the compiled files.
For a faster workflow, run tsc -w and tsc -p tests.json -w in separate command line instances so that the files will be compiled automatically.
Then in a third instance, you can run mocha test -w to run tests on compilation. However, one of the errors running the tests makes mocha fail, so you'll have to fix that before being able to run mocha in watch mode.
It doesn't help that the project hasn't taken the time to fix the many type errors, nor provide any proper documentation on running the tests, so I'd suggest making an issue on GitHub so the authors can take notice.
I am trying to build my project from Task Runner Explorer.
Project is running fine from cmd, using au run.
The error generates is below:
Failed to run "D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\Gulpfile.ts"...
cmd.exe /c gulp --tasks-simple
D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\gulpfile.js:1
(function (exports, require, module, __filename, __dirname) { define(["require", "exports", "gulp", "gulp-shell"], function (require, exports, gulp, gulp_shell_1) {
^
ReferenceError: define is not defined
at Object.<anonymous> (D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\gulpfile.js:1:63)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at execute (D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\node_modules\gulp\node_modules\gulp-cli\lib\versioned\^4.0.0-alpha.2\index.js:37:18)
at Liftoff.handleArguments (D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\node_modules\gulp\node_modules\gulp-cli\index.js:173:63)
I have below code in Gulpfile.ts
import * as gulp from 'gulp';
import shell from 'gulp-shell';
gulp.task('build-dev', shell.task(['au build --env dev']));
Note: I have used both SystemJS and RequireJS module loader.
I am assuming, the issue is simple that i need to tell somehow to use SystemJS loader either in tsconfig.json or package.json or ???
Any help is appreciated. May be I should provide more detail, but could not justify what. Please comment, if any context can help in resolving above issue.
Thanks.
Just in case you're still experiencing this problem;
It appears that the globally installed gulp in C:\Users\{user}\AppData\Roaming\npm\node_modules is an outdated version and that this is where the task runner runs from regardless of what you have defined in your package.json.
In the node.js command prompt, you can uninstall gulp globally using:
npm uninstall gulp -g
As I had gulp declared in my project this actually fixed the problem.
But really what you need is the gulp 4 installed globally;
npm install gulp#next -g
Happy coding!
In Visual Studio Tools->Options->Projects and Solutions->Web Package Management.
Moving $(Path) to first index has resoloved the above issue, may be it was because of node or something else version issue installed independently and in VS.
But still getting another issue at later stage of running task.
The new error is below obviously, it is something else, Can anybody guide a good read overcome these issue:
Failed to run "D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\Gulpfile.ts"...
cmd.exe /c gulp --tasks-simple
C:\Users\irshad.ali\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:147
console.log(Object.keys(localGulp.tasks)
^
TypeError: Cannot convert undefined or null to object
at logTasksSimple (C:\Users\irshad.ali\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:147:22)
at C:\Users\irshad.ali\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:124:14
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3
I have written this as answer but not market as answer, waiting for a great answer. :)
I'm trying to use arrow functions in node v0.10.33 under Ubuntu 14.04 (I'm running node with --harmony flag), but I'm getting this error:
console.log( [1,2,3,4].map(x => x*x) );
^
SyntaxError: Unexpected token >
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
This should work now in node v0.12.x, with the --harmony flag. Also note that you can get arrow functions in node using the babel package.
http://babeljs.io/docs/using-babel/
UPDATE:
As correctly indicated by Mike 'Pomax' Kamermans, the --harmony flag is not required when using Node.js >= 4.x. Please see https://nodejs.org/en/docs/es6/ for more information on the status of ES6 support in Node.js.
Node, even with the harmony flag, doesn't support the fat arrow yet. Source.
Edit: Fun little fact, ES6 support is one of the reasons Node got forked into io.js. Check out their page on ES6 features - they provide a flag for the arrow functions, but discourage using it.
Quite simply, I'm attempting to automate running a nodejs script using cron, however the script itself doesn't seem to be able to run the file. My script is simple:
#!/usr/bin/env node
node /var/node/assets/js/update.js
However, in running this, it returns that the beginning of the pathing is incorrect:
/home/dev/update.sh:2
node /var/node/assets/js/update.js
^^^
SyntaxError: Unexpected token var
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
Is there something actually wrong with the bash, or does node have a specific way of doing this? I used /bin/env so that I could have the proper form of "node" regardless of version.
It looks like you are trying to run node from within node. The error message came from node and it looks like node was trying to run the command /var/node/assets/js/update.js.
I would make the shebang line specify bash rather than node.
The top line
#!/usr/bin/env node
means that what follows should be JavaScript code, not bash.
You are already running node on the first line in an unmodified environment.
then on the second line you supply the command node /var/node/assets/js/update.js to that node process.
How about this:
#!/usr/bin/bash
node /var/node/assets/js/update.js
How about this?
#!/bin/bash
node /var/node/assets/js/update.js