如何用babel处理`npm link`?获得意外的令牌错误

时间:2018-03-20 03:09:03

标签: node.js ecmascript-6 babeljs symlink npm-link

我在父回购(A)上使用npm link来链接子仓库(B)。

npm link正常工作,但Repo A使用babel来转换代码,似乎忽略node_modules依赖关系或符号链接。

我的Repo B中有一个传播操作符,我收到以下错误:

SyntaxError: .../www/adept-him-models/models/event/model.js: Unexpected token (78:10)
  76 |     return full
  77 |       ? {
> 78 |           ...view,
     |           ^
  79 |           // add properties for a full view
  80 |         }
  81 |       : view;

有趣的是,我正在使用节点版本9.4.0,它应该原生支持。

package.json的依赖关系:

  "devDependencies": {
    "apidoc": "^0.17.6",
    "apidoc-markdown": "^0.2.0",
    "babel-eslint": "^8.0.1",
    "babel-jest": "^20.0.3",
    "cross-env": "^5.0.5",
    "dotenv-safe": "^4.0.3",
    "eslint": "^4.4.1",
    "eslint-config-standard": "^10.2.1",
    "eslint-plugin-promise": "^3.0.0",
    "eslint-plugin-standard": "^3.0.1",
    "jest-cli": "^20.0.4",
    "mockgoose": "^6.0.8",
    "nock": "^9.0.2",
    "nodemon": "^1.10.2",
    "opn-cli": "^3.1.0",
    "sinon": "^4.0.1",
    "supertest": "^3.0.0"
  },
  "dependencies": {
    "adept-him-models": "git+ssh://git@github.com/AdeptMind/adept-him-models.git",
    "async": "^2.6.0",
    "babel-core": "^6.26.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-1": "^6.24.1",
    "babel-runtime": "^6.26.0",
    "bluebird": "^3.5.1",
    "body-parser": "^1.18.2",
    "bodymen": "^1.0.3",
    "compression": "^1.7.1",
    "cors": "^2.8.4",
    "express": "^4.16.2",
    "mongoose": "^5.0.11",
    "mongoose-create-unique": "^0.4.4",
    "mongoose-keywords": "^0.3.2",
    "morgan": "^1.7.0",
    "node-random-name": "^1.0.1",
    "querymen": "^2.1.3",
    "random-uri": "^1.0.3",
    "request": "^2.83.0",
    "request-promise": "^4.2.2"
  }

我的.babelrc

{
  "presets": [
    "es2015",
    "stage-1"
  ],
  "plugins": [
    "transform-runtime"
  ]
}

1 个答案:

答案 0 :(得分:0)

将 .babelrc 更改为 babel.config.json 对我有用。