Page 1 of 1

Invalid or unexpected token with JavaScript set up to use nodejs

Posted: Tue Dec 18, 2018 1:41 pm
by paul.obrien@acculink.com
Product, version and build: PrimalScript Version 7.4.118 64 bit
Operating system: Windows 10 Pro 64 bit

I've set up JavaScript to use node.js. When I try and run just a simple program such as...

Code: Select all

console.log('Hello world!');
I get the following error in the output window...

D:\How Tos\nodejs\myHello.js:1
(function (exports, require, module, __filename, __dirname) { ��c
^

SyntaxError: Invalid or unexpected token
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
Execution time: < 1 second
Exit code: 1 , 0001h



I'm not sure where those characters after the "{" are coming from. Here's my settings for JavaScript...

javascript setup.png
javascript setup.png (22.01 KiB) Viewed 7614 times

Re: Invalid or unexpected token with JavaScript set up to use nodejs

Posted: Tue Dec 18, 2018 7:59 pm
by Alexander Riedel
What is the encoding of your source file?

Re: Invalid or unexpected token with JavaScript set up to use nodejs

Posted: Tue Dec 18, 2018 9:51 pm
by Alexander Riedel
The good news is that I get the same result. I also get the same result just running any JS file in a console.
2018-12-18_21-48-55.png
2018-12-18_21-48-55.png (171.45 KiB) Viewed 7595 times
I am not sure what that is but it seems NodeJS related.

Re: Invalid or unexpected token with JavaScript set up to use nodejs

Posted: Tue Dec 18, 2018 9:55 pm
by Alexander Riedel
Ah, NodeJS cannot handle unicode files. Change the file encoding to UTF-8 and it will be fine.
2018-12-18_21-56-21.png
2018-12-18_21-56-21.png (125.04 KiB) Viewed 7593 times

Re: Invalid or unexpected token with JavaScript set up to use nodejs

Posted: Wed Dec 19, 2018 8:04 am
by paul.obrien@acculink.com
That worked - thanks so much for your help!