簡體   English   中英

SyntaxError:在嚴格模式下使用const嗎?

[英]SyntaxError: Use of const in strict mode?

我正在嘗試使用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();

它給出了錯誤:

 /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- npm --version 1.4.28

protractor --version版本3.2.2

selenium-webdriver@2.53.1

更新nodejs解決了該問題:

npm cache clean -f
sudo npm install -g n
sudo n stable
node --version
node app.js

您必須以root / administrator身份運行第二和第三個命令。

n stable不會幫我的忙。 另一方面,

nvm install stable

實際上,這使我使用了最新的nodejs版本。 顯然, n stable v0.12.14對我來說不會通過v0.12.14 我真的不知道為什么

注意: nvm是Node Version Manager,您可以從其github頁面安裝它。 感謝@isaiah指出nvm不是已知命令。

對我來說,解決起來更簡單,只需轉到Node網站,獲取並安裝LTS版本。

更新您的node ,它將解決此問題。

如果您使用的是Windows,只需從節點網站下載並重新安裝LTS或當前版本。

更新NodeJS可解決此問題。 但是,在運行sudo npm install -gn您可能會收到以下錯誤:

npm: relocation error: npm: symbol SSL_set_cert_cb, version libssl.so.10 not defined in file libssl.so.10 with link time reference

為了克服此錯誤,請嘗試使用以下命令升級openssl:

sudo yum update openssl

該錯誤意味着您節點的發布低於需要。 仔細更新計算機的節點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM