0

enter image description here

I'm taking a look at https://github.com/intoli/remote-browser. I'm working in win10 with node 11.5. I've followed the instructions at the bottom of the repo:

# Clone the repository.
git clone https://github.com/intoli/remote-browser.git
cd remote-browser

# Install the dependencies.
yarn install

# Build the project.
yarn build

# Run the tests.
yarn test

Now when I try to run it using :

$ node src/index.js
E:\ENVS\js\remote-browser\src\index.js:1
(function (exports, require, module, __filename, __dirname) { import Browser from './browser';
                                                                    ^^^^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:83:7)
    at createScript (vm.js:267:10)
    at Object.runInThisContext (vm.js:319:10)
    at Module._compile (internal/modules/cjs/loader.js:684:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
    at executeUserCode (internal/bootstrap/node.js:342:17)

How can I get this working?

edit index.js:

import Browser from './browser';
import ConnectionProxy from './connections/proxy';

export default Browser;
export { Browser };
export { ConnectionProxy };
export * from './errors';
export * from './launchers';

edit2:

{
  "name": "remote-browser",
  "version": "0.0.15",
  "description": "A low-level browser automation framework built on top of the Web Extensions API standard. ",
  "main": "index.js",
  "repository": "[email protected]:intoli/remote-browser.git",
  "author": "Intoli, LLC <[email protected]>",
  "license": "BSD",
  "scripts": {
    "build": "Set NODE_ENV=production webpack --config webpack",
    "build:web": "NODE_ENV=production webpack --config webpack/web-client.config.js",
    "postversion": "git push && git push --tags",
    "test": "npm run build && NODE_ENV=test mocha --exit --require babel-core/register",
    "test-fast": "NODE_ENV=test mocha --exit --require babel-core/register --invert --grep Browser",
    "watch": "NODE_ENV=development webpack --watch --config webpack"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-eslint": "^8.0.2",
    "babel-loader": "^7.1.2",
    "babel-plugin-transform-builtin-extend": "^1.1.2",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "clean-webpack-plugin": "^0.1.17",
    "copy-webpack-plugin": "^4.2.1",
    "eslint": "^4.11.0",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-loader": "^1.9.0",
    "eslint-plugin-import": "^2.8.0",
    "imports-loader": "^0.7.1",
    "jimp": "^0.2.28",
    "mocha": "^4.0.1",
    "null-loader": "^0.1.1",
    "source-map-support": "^0.5.0",
    "webextension-polyfill": "^0.2.1",
    "webpack": "^3.8.1",
    "webpack-chrome-extension-reloader": "^0.6.6"
  },
  "dependencies": {
    "chromedriver": "^2.37.0",
    "express": "^4.16.2",
    "express-ws": "^3.0.0",
    "geckodriver": "^1.11.0",
    "isomorphic-fetch": "^2.2.1",
    "portfinder": "^1.0.13",
    "selenium-webdriver": "^4.0.0-alpha.1",
    "simple-websocket": "^5.1.0",
    "ws": "^3.3.2"
  }
}
9
  • Possible duplicate of ES6 import gives Unexpected Identifier SyntaxError when running on terminal Commented Aug 20, 2019 at 14:56
  • 1
    Maybe showing us that vm.js file and especially lines around 83 would be fine Commented Aug 20, 2019 at 14:56
  • 1
    You can't do an import statement inside a function. Commented Aug 20, 2019 at 14:58
  • Doesn't Node support import yet? How come implementing this standard ES6 feature take such a long time? Commented Aug 20, 2019 at 14:59
  • @JeremyThille Node does support it, but in any environment import must be at the global (module) level, not inside of a function. Commented Aug 20, 2019 at 14:59

1 Answer 1

1

You can't run node src/index.js. When you run yarn build it will create a new folder dist in the root folder, which has all the source code. Go to this folder and find the index.js file, open this to learn more.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Tran, didn't know that. I've added the package.json file above, but I am not seeing dist in the root directory, so something is wrong and I guess the build did not happen.
You can go here https://github.com/intoli/remote-browser/blob/master/webpack/client.config.js to view how to project build. It has an output that have path: path.resolve(__dirname, '..', 'dist'),. This means it will build source to dist file. To learn more, please learning webpack to learn how this build your source.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.