Babel does not find a plugin

Viewed 1375

I have an app module and common module that is shared by several app modules.

- 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",
}

common/package.json

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

common code is in es6 and needs to be transpiled in app so webpack.config.js contains

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

Everything works fine if I run yarn install in common module, then in app module. That copies complete node_modules of common module so it contains all dev deps including babel-plugin-transform-object-rest-spread.

If I remove node_modules from common module, run yarn install app module, only prod dependencies are copied and babel-plugin-transform-object-rest-spread is missing in app/node_modules/common/node_modules. I then get

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"

because babel-plugin-transform-object-rest-spread is missing in app/node_modules/common/node_modules. The package is already in app/node_modules so there should be no problem but babel wants it right in the common package? How can I tell babel to use the root level dependency?

0 Answers
Related