Unexpected Token = getting while running the following code - node.js

I'm getting the following error while running the below. The issue is with the unexpected toke "=". Due to which I'm getting the error.
# ./yarn install
/var/jenkins_home/jobs/in-install/workspace/yarn-bin/yarn-1.15.2.js:1227
var _ref27 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (dir,relativeDir, ignoreBasenames = new Set()) {
SyntaxError: Unexpected token =
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 Function.Module.runMain (module.js:441:10)
at startup (node.js:140:18)
at node.js:1043:3
Nodejs version 4.8.3

function* (dir,relativeDir, ignoreBasenames = new Set() uses default parameters.
Node.js 4.8.3 does not support default parameters for functions. You will need to use at least Node.js 6.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters

Related

Error installing Vue3 on the command line

I acted according to the video tutorial Laravel 9 and Vue 3 SPA online store 10. Creating a project on vue3, the client part of the online store. See from 1:00-3:00. When executing the command
npm init vue#latest
I received an error
Microsoft Windows [Version 6.1.7601]
(c) Корпорация Майкрософт (Microsoft Corp.), 2009. Все права защищены.
C:\Windows\system32>cd C:\OpenServer\domains\clientpart
C:\OpenServer\domains\clientpart>npm init vue#latest
npx: installed 1 in 31.943s
C:\Users\1\AppData\Roaming\npm-cache\_npx\7892\node_modules\create-vue\outfile.c
js:3856
const isFeatureFlagsUsed = typeof (argv.default ?? argv.ts ?? argv.jsx ?? argv
.router ?? argv.pinia ?? argv.tests ?? argv.vitest ?? argv.cypress ?? argv.eslin
t) === "boolean";
^
SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js
:60:12)
at internal/main/run_main_module.js:17:47
C:\OpenServer\domains\clientpart>npm -v
6.14.4
C:\OpenServer\domains\clientpart>npm init vue#latest
npx: installed 1 in 2.887s
C:\Users\1\AppData\Roaming\npm-cache\_npx\10624\node_modules\create-vue\outfile.
cjs:3856
const isFeatureFlagsUsed = typeof (argv.default ?? argv.ts ?? argv.jsx ?? argv
.router ?? argv.pinia ?? argv.tests ?? argv.vitest ?? argv.cypress ?? argv.eslin
t) === "boolean";
^
SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js
:60:12)
at internal/main/run_main_module.js:17:47
C:\OpenServer\domains\clientpart>
Tell me how to fix the error and achieve the correct installation of vue.
This error happens because you are using a version of node.js other than 16. You can check the version using the command node --version. I recommend using NVM to manage your node.js versions

installing with NPM gives out error:2406C06E:random number generator

I'm using Ubuntu server 18.04.
Every time I try to use NPM it crashes and shows the following exception:
internal/crypto/random.js:119
if (ex) throw ex;
^
Error: error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy
at Object.randomBytes (internal/crypto/random.js:54:31)
at /usr/lib/node_modules/npm/lib/npm.js:444:32
at Object.<anonymous> (/usr/lib/node_modules/npm/lib/npm.js:496:3)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at /usr/lib/node_modules/npm/bin/npm-cli.js:28:13 {
opensslErrorStack: [
'error:2406B072:random number generator:RAND_DRBG_generate:in error state',
'error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy',
'error:2406B072:random number generator:RAND_DRBG_generate:in error state',
'error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy'
]
}
Does anybody has any idea of what could be wrong?

SyntaxError when declaring a class in TypeScript

I'm getting an error when declaring a class:
// This is all on my test1.ts file content
class WDesign {
wModel: string;
wQuer: string;
}
let logWDesign = (wd : WDesign) => {
console.log(wd.wModel + " " + wd.wQuer);
}
let wd1 : WDesign;
wd1.wModel = "SDS-9985";
wd1.wQuer = "escarni";
logWDesign(wd1);
Then, to show on Node command prompt:
>node test1.ts
I get the following:
[filePath].test1.ts:3
wModel: 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
Typescript ver 3.1.3
Node ver. 8.12.0
Visual Studio Code 1.28.2
You firstly have to transpile the .ts file .js by simply running the command
tsc
node test1.js
This will generate javascript corresponding to your typescript files. Node cannot directly understand typescript. You have to give it javascript code.
You can use typescript-node-starter code provided by Typescript here to save configuration hustle.
Post comments if further help is required.

installing and running browsershots

I tried to install Brwoswershots (https://github.com/spatie/browsershot) and I did this exactly by following the instructions on github.
Installing NodeJS and npm via yum
Installing browswershoots via composer: composer require
satie/browsershot
crated a file with
use Spatie\Browsershot\Browsershot;
$pathToImage="img/testasdf.png";
// an image will be saved
Browsershot::url('https://example.com')
->setScreenshotType('jpeg', 100)
->save($pathToImage);
It is on http://textblob.com/browsershots.php and brings the error.
Fatal error: Uncaught
Symfony\Component\Process\Exception\ProcessFailedException:
The command "PATH=$PATH:/usr/local/bin NODE_PATH=`npm root -g` node
'/home/textblob/public_html/vendor/spatie/browsershot/src/../bin/browser.js'
'{"url":"https:\/\/example.com",
"action":"screenshot",
"options": {
"type":"jpeg",
"path":"img\/testasdf.png",
"quality":100,
"args":[],
"viewport":{"width":800,"height":600}
}
}'"
failed. Exit Code: 1(General error) Working directory:
/home/textblob/public_html
Output: ================ Error Output: ================
/home/textblob/public_html/vendor/spatie/browsershot/bin/browser.js:5
const getOutput = async (page, request) =>
{ ^ SyntaxError: 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.runMa in /home/textblob/public_html/vendor/spatie/browsershot/src/Browsershot.php
on line 565
I could solve this by downgrading to boxshot v2, witch works without puppeteer and so its not a fix, but working for me.

Node.js - Error Unexpected Identifier

I'm using ubuntu 16.04 on vagrant to run this node.js.
node version is v6.2.2.
this is my code. i try to browsing for the solution using the keyword "SyntaxError: Unexpected identifier" but no luck.
function SignalFire(ID, startingLogs) {
this.fireID = ID;
this.logsLeft = startingLogs;
}
SignalFire.prototype = {
addLogs: function(numLogs) {
this.logsLeft += numLogs;
}
lightFire: function() {
console.log("Whooosh!");
}
}
this is the error i got:
/vagrant/inheritance.js:11
lightFire: function() {
^^^^^^^^^
SyntaxError: Unexpected identifier
at Object.exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:513:28)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (node.js:348:7)
at startup (node.js:140:9)
at node.js:463:3
Can you please help me with this?

Resources