I'm trying to get a protactor test running. But when making use of module it throws the below. I'm quite new to ES6 how to configure it.
export { getFreePort }; ^^^^^^ SyntaxError: Unexpected token export at Object.exports.runInThisContext (vm.js:76:16) at Module._compile (module.js:513:28) at Module._extensions..js (module.js:550:10) at Object.require.extensions.(anonymous function) [as .js] (C:\\Dev\\Code\\JG.Crowdfunding.Website\\node_modules\\babel-register\\lib\\node.js:156:7) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.require (module.js:468:17) at require (internal/module.js:20:19) at Object. (C:\\Dev\\Code\\JG.Crowdfunding.Website\\protractor.conf.js:4:18)
My babelrc file has
{ "presets": ["es2015"] }
The imported file where the error occurs looks like
var freeport = require('freeport');
var getFreePort = function () {
return new Promise((fulfill, reject) => {
freeport((err, port) => {
if (err) {
console.log('ERROR: Something went wrong while trying to find a free port.');
reject(err);
}
fulfill(port);
});
});
};
export { getFreePort };
And inside my protractor.conf onPrepare function I have.
onPrepare: function () {
return portHelper.getFreePort().then(port => {
fakeApiServer.startFakeApiServer(port);
}).then(() => {
return browser.driver.manage().window().maximize();
})}
and I'm doing the following further up in the protractor.conf
require('babel-core/register');
var portHelper = require('./test/e2e/helpers/portHelper');
Thanks
在此行中,您需要在括号中添加port
: return portHelper.getFreePort().then(port => {
As it turns out my error was that babel-register ignores the node_modules folder. In order to solve my problem I needed to do
require('babel-core/register')({ ignore: false });
Instead of just
require('babel-core/register');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.