IntelliJ: why does Node.js launcher crash in debug mode? - node.js

I wrote a very simple Typescript file and called it "app2.ts".
I created the following launcher in IntelliJ:
When I run this launcher, everything works properly. However, when I run it in debug mode, I get the following error in console:
(function (exports, require, module, __filename, __dirname) {
SyntaxError: Invalid or unexpected token
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 Module.require (internal/modules/cjs/loader.js:637:17)
at Module._preloadModules (internal/modules/cjs/loader.js:824:12)
Do you know what is the problem and why the configuration works in run mode, and doesn't work in debug mode?

Related

Run native Nodejs in AS400 / iSeries

I'm trying to run Node.js on AS/400 server in order to use Node.js toolkit for IBM i.
I have installed Node v6.14.4 and NPM 3.10.10 and I'm following this documentation to test node.js: https://developer.ibm.com/articles/i-native-js-app-ibmi-with-nodejs/#access-ibm-i-native-objects
I created the sample javascript file and when I run (from PASE terminal), I get this error:
node /home/njs/sample.js
/sample.js:1
(function (exports, require, module, __filename, __dirname) { #����ï¿
½ï¿½ï¿½K���M È ï¿½ï¿½#����� ]^
SyntaxError: Invalid or unexpected token
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.runMain (module.js:611:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:160:9)
I supposed there is a problem with npm and I tried with a very simple js file (an only one console.log) and I get the same error.
I have solved my issue. It was because an enconding problem.
I was creating javascript files with EDTF on AS/400 environment and that was a problem. I created a new file with notepad and upload by Navigator for i and works properly.

How to fix the following error creating a node js class?

Hello I started creating a node.js class as follows:
'use strict';
let {google} = require('googleapis')
class Calendar {
calendarId : string;
However, when I test my code I got:
src/utilities/calendar.ts:6
calendarId : string;
^
SyntaxError: Unexpected token :
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
So I don't understand why I am getting that, I would like to appreciate suggestions to overcome the issue. My Node version is 8.16.0 and I am also using typescript
You are writing a typescript file, not a javascript file.
Node cannot automatically run typescript files. You need to:
install typecript
compile the file
run the output with node.js
Alternatively you could use a node like ts-node to execute your typescript right from the command-line.

I have just the Started the learning the Type Script ans getting the below error.please help on this and what could be the mistake?

var n:string = "mary";
D:\Angular\TS>node Untitled_2.ts
D:\Angular\TS\Untitled_2.ts:1(function (exports, require, module,
__filename, __dirname) { var n:string = "mary";
^
SyntaxError: Unexpected token :
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:607:28)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
Your problem is that you have to compile Typescript code before you can run it with node. You can do this two ways.
Run tsc Untitled_2.ts and then run node Untitled_2.js (assuming no extra config that changes output paths)
Install ts-node and run ts-node Untitled_2.ts
You may need to prefix the above commands with npm run or yarn to add the command to your path.

kue - Unexpected token import

Hi I am trying to import my class in worker and getting following error
(function (exports, require, module, __filename, __dirname) { import { Myclass } from '../utility/myclass';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
I also get error in following
async function getOrder() : Promise<any> {
^
SyntaxError: Unexpected token :
I am using typescript and have included type files for kue. I run the worker from command line and it looks like it is able to understand the env... not sure whats wrong ..
It seems you running the code without ES6 support.
You need to use babel-cli to run this code, it will compile the code to ES6 before running it.
babel-node yourscript.js

Error while running Node.js program on IBM i (previously known as iSeries or AS/400)

IBM i Version : V7R2M0
node installation path: /QOpenSys/QIBM/ProdData/Node/bin
node -v : v0.12.17
I've created a simple console.log('hello world') program, while running getting following error
$ cd /QOpenSys/QIBM/ProdData/Node/bin
$ node /home/anoop/index.js
function (exports, require, module, __filename, __dirname) {
yntaxError: Unexpected token
ILLEGAL
at exports.runInThisContext
(vm.js:73:16)
at Module._compile
(module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
It is related to CCSID of file. You need to create file with 1208 CCSID or an ASCII codepage. So file is created as follows
$ touch -C 1208 index.js

Resources