webpack-node-externals icon indicating copy to clipboard operation
webpack-node-externals copied to clipboard

Node's optionalDependencies are not working

Open davidyaha opened this issue 8 years ago • 0 comments

Hey,

This package is great! I am certainly not an expert with webpack config files but I've came across this issue where I had an optional package and using this, webpack just couldn't figure out that it is optional. It relates to the change webpack did here https://github.com/webpack/webpack/commit/51046618551c5789d8ba1c7a7692b19a5aed12d1 It seems that webpack recognises optional packages when the externals object is directing to the global package name like so:

externals: {
    "redux-logger": "redux-logger", // This is described in optionalDependency
  },

A quick workaround is to chain optional packages with the nodeExternals() function like so:

externals: [
    nodeExternals(), {
    "redux-logger": "redux-logger",
  }],

I am not sure if this is fixable in any other way (maybe by checking the optional flag and calling the callback with the simplified name of the package...) But this thing should at least be noted on the docs.

Thanks again for this package!

davidyaha avatar Jan 09 '17 16:01 davidyaha