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? - node.js

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.

Related

SyntaxError: Unexpected token ... in serialport in node_modules

I hav been trying to run the vue-electron app. But the following error comes.
App threw an error during load
C:\newFolder02\pos4-desktop\node_modules\#serialport\stream\lib\index.js:103
const settings = { ...defaultSettings, ...options }
^^^
SyntaxError: Unexpected token ...
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\newFolder02\pos4-desktop\node_modules\serialport\lib\index.js:1:175)
The error comes from the following line.
const settings = { ...defaultSettings, ...options }
I use following tools
node 8.16.0
npm 6.4.1
electron 1.8.2
It doesn't work in Windows. But it works in Mac OS.
Any idea..?
I have found a solution. You can convert the ES6 code to original JavaScript code with Babel(https://babeljs.io/en/repl).
I converted the ES6 code to vanilla JavaScript through Babel. I ticked ENV PRESET in left sidebar. I set Electron to "1.8" and Node to "8.16". It worked well.
Babel Screenshot

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.

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?

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