SyntaxError: Use of const in strict mode? - node.js

I am trying to login on facebook.com with selenium-webdriver.
var webdriver = require('selenium-webdriver'),
By = require('selenium-webdriver').By,
until = require('selenium-webdriver').until;
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get('https://www.facebook.com/login');
driver.findElement(By.id('email')).sendKeys('****');
driver.findElement(By.id('pass')).sendKeys('*****');
driver.findElement(By.id('loginbutton')).click();
driver.findElement(By.linkText('Settings')).then(function(element) {
console.log('Yes, found the element');
}, function(error) {
console.log('The element was not found, as expected');
});
driver.quit();
It is giving error:
/home/shubham/node_modules/selenium-webdriver/index.js:25
const builder = require('./builder');
^^^^^
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/shubham/Music/amazon_login/test_22_4_16/sel_login.js:1:79)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
node --version v0.10.37
npm --version1.4.28
protractor --version Version 3.2.2
selenium-webdriver#2.53.1

Updating nodejs solved the issue:
npm cache clean -f
sudo npm install -g n
sudo n stable
node --version
node app.js
You have to run the second and third command as root/administrator.

n stable wouldn't do the trick for me. On the other hand,
nvm install stable
That actually got me to last nodejs version. Apparently n stable won't get pass v0.12.14 for me. I really don't know why.
Note: nvm is Node Version Manager, you can install it from its github page. Thanks #isaiah for noting that nvm is not a known command.

For me it was more simple to solve, just going to the Node web site, get and install the LTS version.

Update your node and it will resolve this problem.

Updating NodeJS solves this problem.
But, after running sudo npm install -g n you might get following error:
npm: relocation error: npm: symbol SSL_set_cert_cb, version libssl.so.10 not defined in file libssl.so.10 with link time reference
In order to overcome this error, try upgrading openssl using the below command:
sudo yum update openssl

That error means your node's publish is low than the need.
carefully to update the node of your computer.

Related

Node error: "SyntaxError: Unexpected token {" at "const {join, basename} = require('path')"

I need to work with an app based on ionic framework v1 and Cordova 7.1, but there is the following problem with Node when running Cordova:
$ cordova -v
/node_modules/cordova/node_modules/npm-normalize-package-bin/index.js:3
const {join, basename} = require('path')
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (node_modules/cordova/node_modules/read-package-json/read-json.js:14:27)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
I installed Cordova with this command:
npm install -g cordova#7.1.0
The project requires the following versions which are installed on my machine:
node -v
v5.12.0
npm -v
3.8.6
ionic -v
1.7.15
grunt --version
grunt-cli v0.1.13
grunt v0.4.5
bower -v
1.8.4
plugman -v
2.0.0
Does anyone have a clue where the problem is? I'm glad for any help.
The problem is that nodejs v5.x doesn't support destructuring, which is used in the line
const {join, basename} = require('path')
You can read more about supported js features in nodejs here, https://node.green/#ES2015-syntax-destructuring--declarations
Cordova depends on "init-package-json" which in turn depends on "read-package-json: 1 || 2".
Now there's been an update to "read-package-json" some months ago which introduces a new dependency to "npm-normalize-package-bin". This package makes use of a syntax construct that's apparently supported not before node 6.0.0.
So, if updating node is not an option (which is recommended, since node 5 - 8 is end-of-life), you may install this (also rather outdated) cordova locally (inside the project folder) and overwrite the read-package-json dependency there by npm i read-package-json#2.0.13.
Edit: Call cordova via npx: npx cordova -v
Thank you all for your helpful inputs to better understand the cause.
Unfortunately, updating node was not an option. In the end, I compared my Cordova installation with a teammate who does not have this problem. The only difference was that his 'cordova/node_modules/npm-normalize-package-bin' was not present where the error is triggered. So I deleted this package from my system to solve the problem.
Maybe this will help somebody else.

Ember Installation Issue: SyntaxError: Use of const in strict mode

When trying to install Ember.js on Windows (and possibly other systems), after running the following commands:
npm install -g npm
npm install -g ember-cli
npm install -g bower
No errors are raised, how the command ember -v outputs the following:
C:\Users\<user>\AppData\Roaming\npm\node_modules\ember-cli\lib\cli\index.js:3
const willInterruptProcess = require('../utilities/will-interrupt-process');
^^^^^
SyntaxError: Use of const in strict mode.
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 Module.require (module.js:365:17)
at require (module.js:384:17)
at C:\Users\Shayn\AppData\Roaming\npm\node_modules\ember-cli\bin\ember:26:11
at C:\Users\Shayn\AppData\Roaming\npm\node_modules\ember-cli\node_modules\resolve\lib\async.js:50:13
at processDirs (C:\Users\Shayn\AppData\Roaming\npm\node_modules\ember-cli\node_modules\resolve\lib\async.js:182:39)
This suggests an issue with my Ember installation, how can I address this?
The solution is suggested in a few other answers, for example this one, however this exact solution will not work on Windows.
Instead, the best solution is to get the latest version of Node installed via an installer.
To verify after installation try the following:
node --version
Which should output something like:
v8.9.1
Previously this command would have given a lower version number. In my case it was similar to v0.12.

ubuntu nodejs syntax error Syntax Error: Unexpected token `

I went through the process of installing the VolumioUI on Ubuntu
as explained in this link.
and I get:
/Volumio2-UI$ gulp serve --theme="volumio"
/home/yossi/elia/Volumio2-UI/gulp/build.js:127
fs.readFileSync(`${conf.paths.src}/app/themes/${themeSelected}/assets/va
^
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /home/yossi/elia/Volumio2-UI/gulpfile.js:19:3
at Array.map (native)
at Object.<anonymous> (/home/yossi/elia/Volumio2-UI/gulpfile.js:18:4)
at Module._compile (module.js:456:26)
I did the same process on MAC with no problems.
This is very strange since it complains about a syntax error.
if I change it to ' than it works fine, the problem is that the code is full of this error.
Can I config NodeJs to treat ` as '
?
Note: I was able to solve it by search-and-replace, but I leave this question open because I would like to know if it can be solved with a config
$ node --version
v0.10.25
Backticks are part of the new syntax introduced in the latest version of Javascript (ES6).
The problem occurs, because you have a (very) old version of node, which does not implement this new syntax. Probably, you have node v.0.10 instead of node v.7
The solution is to upgrade node.js.
Here is how (Ubuntu 14), see https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/nodejs
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
This is the solucion with the problem for Invalid or unexpected token when you use npm install.
Backticks are different from single quotes, they aren't interchangeable by means of setting a configuration option somewhere.
You need a relatively recent Node.js version (v4.4.2 or up, I think) that supports the backtick ("template literal") syntax.

MEAN stack, cannot find module 'request'

I'm new to mean stack world, I installed mongoDB and nodejs
node -v => v4.4.3
npm -v => 2.15.1
mongo -version => MongoDB shell version: 3.2.6
then followed MEAN installation guide to install it.
after many faults I can run gult and have a response.
now when ever I try to run any command with mean, I get following error:
module.js:327
throw err;
^
Error: Cannot find module 'request'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/lib/node_modules/mean-cli/lib/controllers/anonymized-data.js:8:12)
at Module._compile (module.js:409:26)
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)
I tried with: sudo npm install request
but still getting same issue !! can any one guide me please? thanks in advance
UPDATE
after running command given by #Alexander Mac, I got following result
it's still same status :( . and without sudo I got lots or errors #Seth :P
Alex is right about 'request' not being part of the package. That said, instead of messing out with the install manually, it might be far easier to install a previous known good version
For e.g., you can try: sudo npm i -g mean-cli#0.12.1
mean-cli package has a bug. The authors forget to include request module in package.json: look here. You can create an issue about that on their site.
To resolve the problem locally go to /usr/lib/node_modules/mean-cli and run: sudo npm i request to install missing request module.
I use nvm to manage node.
I go to /home/ougwen1235/.nvm/versions/node/v4.2.4/lib/node_modules/mean-cli and run npm install request --save.Then, the problem was solved.

What's wrong with my typescript compiler? `tsc --version` returns nothing

In Linux Mint, I've installed node and used it to install typescript. With a working typescript installation, tsc --version should return the version number. In my case, nothing is returned at all.
When I run which tsc the result is /usr/local/bin/tsc.
When I run cat /usr/local/bin/tsc the result is:
#!/usr/bin/env node
require('../lib/tsc.js')
When I run find /usr/local -name 'tsc*' the result is:
/usr/local/bin/tsc
/usr/local/lib/node_modules/typescript/bin/tsc
/usr/local/lib/node_modules/typescript/lib/tsc.js
Does that look correct? If so, then any ideas on what else to look at would be appreciated?
Note I also tried running /usr/local/lib/node_modules/typescript/bin/tsc --version and got the same result ie nothing.
In my case on Ubuntu 16.04 the problem was because of I performed sudo apt-get install node-typescript, which delivered me broken tsc. After removing it via apt-get remove and then installing as recommended with npm install -g typescript, it worked fine.
Maybe this will help someone.
I discovered that running node --version returns nothing (but shouldn't) however nodejs --version works (the result being v0.10.25). Reinstalling node didn't fix this. I don't know why this would be the case, as I think I followed the recommended installation procedure.
However, editing file /usr/local/bin/tsc and changing the line:
#!/usr/bin/env node
to
#!/usr/bin/env nodejs
seemed to work. Now tsc --version returns message TS6029: Version 1.6.2 and I'm getting .js files generated when I run make.
I was getting the following error in Ubuntu 16.04.6 :
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'typescript/tsc.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/bin/tsc:2:1)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
Running : npm install -g typescript didn't resolved the issue.
So, I had to install the latest version of node i.e nvm install <nvm version>
Then with npm install , it fixed the issue.

Resources