【问题标题】:How to handle `npm link` with babel? Getting unexpected token error如何用 babel 处理`npm link`?收到意外的令牌错误
【发布时间】:2018-03-20 03:09:02
【问题描述】:

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

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

我的回购 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"
  ]
}

【问题讨论】:

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-12
    • 2019-10-06
    • 1970-01-01
    • 2020-11-16
    • 2016-07-01
    • 2018-09-23
    • 1970-01-01
    • 2016-11-28
    相关资源
    最近更新 更多