5

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?

T. Vojtech
  • 51
  • 1
  • 4
  • This sounds like expected behavior. Babel looks for plugins relative to the `.babelrc` file, so if they aren't in `common` it won't work. – loganfsmyth Aug 09 '17 at 17:58
  • Is there a way to tell Babel to look at top level deps? Node.js tries to find dependecy at top level if it's missing in place. Problem is that yarn/npm does dedupe and the plugin ends only at top level. – T. Vojtech Aug 13 '17 at 18:55

0 Answers0