Babel找不到插件

时间:2017-08-09 07:58:06

标签: javascript webpack ecmascript-6 babeljs babel-loader

我有一个app模块和几个app模块共享的通用模块。

- app
  - src
  - package.json
  - webpack.config.json
  - .babelrc
- common
  - lib
  - package.json
  - .babelrc

app / package.json

dependencies: {
  common: "../common"
},
devDependencies: {
  ...othe deps,
  "babel-plugin-transform-object-rest-spread": "^6.23.0",
}

公共/的package.json

devDependencies: {
  ..other deps,
  "babel-plugin-transform-object-rest-spread": "^6.23.0",
}

常用代码在es6中,需要在app中进行转换,以便webpack.config.js包含

{
  test: /\.js/,
  exclude: /node_modules\/(?!(ui-common|ui-server-common)\/).*/,
  loader: 'babel-loader',
},

如果我在公共模块中运行yarn install,然后在app模块中运行,一切正常。这会复制公共模块的完整node_modules,因此它包含所有开发人员,包括babel-plugin-transform-object-rest-spread。

如果我从公共模块中删除node_modules,运行yarn install app模块,只会复制prod依赖项,并且app / node_modules / common / node_modules中缺少babel-plugin-transform-object-rest-spread。然后我得到

Module build failed: ReferenceError: Unknown plugin "transform-object-
rest-spread" specified in "/Users/blaf/projects/management-
ui/ui-common/.babelrc" at 0, attempted to resolve relative to 
"/Users/blaf/projects/management-ui/ui-common"

因为app / node_modules / common / node_modules中缺少babel-plugin-transform-object-rest-spread。该软件包已经在app / node_modules中了,所以应该没有问题,但是babel想要在公共软件包中使用它?如何告诉babel使用根级依赖?

0 个答案:

没有答案