nodejs:SyntaxError:意外的标识符

时间:2019-08-20 14:54:55

标签: javascript node.js

enter image description here

我正在看https://github.com/intoli/remote-browser。我正在使用节点11.5在win10中工作。我已经按照仓库底部的说明进行操作了:

# 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

现在,当我尝试使用:

$ 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)

我该如何工作?

编辑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": "git@github.com:intoli/remote-browser.git",
  "author": "Intoli, LLC <contact@intoli.com>",
  "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"
  }
}

1 个答案:

答案 0 :(得分:1)

您无法运行node src/index.js。运行yarn build时,它将在根文件夹中创建一个包含所有源代码的新文件夹dist。转到该文件夹​​并找到index.js文件,打开该文件以了解更多信息。