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

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

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.

PM2 - SyntaxError: Block-scoped declarations not yet supported outside strict mode

I'm currently installing a NodeJS service on an Ubuntu server. The application is written in coffeescript and runs fine on it's own. This is how I setup the project:
cd ~/test-project
nvm use v4.9.1
npm install
pm2 start index.js
However when I try to start it using pm2 i get the error below:
/usr/local/lib/node_modules/pm2/node_modules/needle/node_modules/debug/src/node.js:132
let val = process.env[key];
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/local/lib/node_modules/pm2/node_modules/needle/node_modules/debug/src/index.js:9:19)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
And after doing some testing it seems that this error occurs no matter what script I start with pm2 so there must be something that isn't configured correctly..
I don't know if it matters but the script I am trying to run needs node v4.9.1 so I am using NVM to use that version, it seems to me that it is trying to run pm2 with that same node version somehow?
Any input is greatly appreciated as I've been stuck on this for way too long!!
I had the same issue on node version 4.x,
Downgraded the pm2 and it worked.
npm uninstall -g pm2
npm install -g pm2#3.0.4
'use strict';
Add above line of code to first line of the script file. let is used when you want a variable to be scoped to a block which is supported in strict mode in node v4.
See the documentation for more details.
#Vishnu Sing this is the complete output. The index.js file looks like this:
console.log('Hello World');
ubuntu#ip-172-31-32-5:~/test-project$ nano index.js
ubuntu#ip-172-31-32-5:~/test-project$ node -v
v10.15.3
ubuntu#ip-172-31-32-5:~/test-project$ sudo pm2 start index.js
/usr/local/lib/node_modules/pm2/node_modules/needle/node_modules/debug/src/node.js:132
let val = process.env[key];
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/local/lib/node_modules/pm2/node_modules/needle/node_modules/debug/src/index.js:9:19)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
ubuntu#ip-172-31-32-5:~/test-project$

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

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?

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.

nodejs SyntaxError: Unexpected token

I am using elasticsearch-exporter to export data from Elasticsearch.
The tool initially is a nodejs application.
When I try to use the following command node exporter.js to make the tool list all the available options, it crashes with the following exception
/home/me/storage/Elasticsearch-Exporter/log.js:54
exports.error = (...args) => !capture("ERROR", args) && console.log(timestamp() + util.format(...args).red);
^^^
SyntaxError: Unexpected token ...
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/anas/storage/Elasticsearch-Exporter/exporter.js:9:11)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
here is the line where the exception is thrown
exports.error = (...args) => !capture("ERROR", args) && console.log(timestamp() + util.format(...args).red);
I think the error is related to a different version of nodejs but I am not sure.
Here is the output of the node --version command v4.2.6
Here is the output of the npm --version command 3.10.6
Yes, indeed, ... is called the spread operator and is only available since Node.js 6
The elasticsearch-exporter project declares in its package.json file that it only works with node version > 6
So since you're running Node.js 4.2.6, you either need to upgrade your Node.js installation or fork the elasticsearch-exporter project and modify it to work with Node.js 4.2.6.

Resources