node.js SyntaxError:在严格模式下使用 const?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36789889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:08:25  来源:igfitidea点击:

SyntaxError: Use of const in strict mode?

node.jsseleniumselenium-webdriver

提问by Shubham Batra

I am trying to login on facebook.com with selenium-webdriver.

我正在尝试使用 selenium-webdriver 登录 facebook.com。

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)
/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 --versionv0.10.37

node --versionv0.10.37

npm --version1.4.28

npm --version1.4.28

protractor --versionVersion 3.2.2

protractor --version版本 3.2.2

[email protected]

[email protected]

回答by tenbits

Updating nodejssolved the issue:

更新nodejs解决了这个问题:

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.

您必须以 root/管理员身份运行第二个和第三个命令。

回答by Alf Sanzo

n stablewouldn't do the trick for me. On the other hand,

n stable不会为我做的伎俩。另一方面,

nvm install stable

That actually got me to last nodejs version. Apparently n stablewon't get pass v0.12.14for me. I really don't know why.

这实际上让我到了最后一个 nodejs 版本。显然n stable不会让v0.12.14我通过。我真的不知道为什么。

Note: nvmis Node Version Manager, you can install it from its github page. Thanks @isaiah for noting that nvmis not a known command.

注意:nvm是 Node 版本管理器,你可以从它的 github 页面安装它。感谢@isaiah 注意到这nvm不是一个已知的命令。

回答by Pedro Benevides

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

对我来说,解决起来更简单,只需访问Node网站,获取并安装 LTS 版本即可。

回答by Root

Update your nodeand it will resolve this problem.

更新您的node,它将解决此问题。

回答by Dibya Sahoo

Updating NodeJS solves this problem. But, after running sudo npm install -g nyou might get following error:

更新 NodeJS 解决了这个问题。但是,运行后,sudo npm install -g n您可能会收到以下错误:

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:

为了克服此错误,请尝试使用以下命令升级 openssl:

sudo yum update openssl

回答by user6531209

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

该错误意味着您节点的发布低于需要。仔细更新您计算机的节点。