kue - Unexpected token import - node.js

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

Related

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.

Render error. Exception: (function (exports, require, module, __filename, __dirname) { class {

when i start server with npm test the error above is shown but when i run server and test separately it works fine
detailed error message is :
Render error. Exception: /home/irisind/Akhil/myproj/components/app-head/index.marko:1
(function (exports, require, module, __filename, __dirname) { class {
^
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)
console.error node_modules/koa/lib/application.js:185
In order to use Marko within Jest you should use https://github.com/marko-js/jest since Jest does not support traditional require hooks.
In order to use Marko on the server side you will need to register the require hook:
https://markojs.com/docs/installing/#require-marko-views

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.

Import keyword is not recognized by gulp throwing SyntaxError: Unexpected reserved word

Failed to load external module babel-core/register
Failed to load external module babel/register
somelocation\gulpfile.babel.js:27
import fs from 'fs';
^^^^^^
SyntaxError: Unexpected reserved word
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:413:25)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Liftoff.handleArguments (\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:116:3)
at Liftoff.<anonymous> (\AppData\Roaming\npm\node_modules\gulp\node_modules\liftoff\index.js:192:16)
at module.exports (\AppData\Roaming\npm\node_modules\gulp\node_modules\liftoff\node_modules\flagged-respawn\index.js:17:3)
I am getting this error while trying to run gulp after npm as described here: deploy-appengine.md. How to fix it?
EDIT: as Luke Bennet points out correctly in a comment to this answer, it was indeed JavaScript - the ES6 "import" syntax. The issue is that this won't work out of the box in Node as yet.
You seem to be using the python module import syntax in NodeJS. You should use the NodeJS module require syntax.

Resources