npm linked modules resolve ProvidePlugin dependencies wrong

I have Project, which depends on a node module Dep. Dep uses fetch in its source code, but doesn’t provide a polyfill. Project provides a polyfill for fetch like so:

  plugins: [
    new webpack.ProvidePlugin({
      fetch: 'isomorphic-fetch'
    })
  ]

I’m making changes to Dep, so I linked it in using npm link. Dep is now a symlink in my node_modules.

When I run a build webpack tries to resolve isomorphic-fetch from Dep/node_modules instead of Project/node_modules, which throws an error because isomorphic-fetch doesn’t exist there.

Webpack version: 1.13.0
Node version: 6.9.2

Temporary fix

I’ve added the following to my config to override the module resolution:

  resolve: {
    alias: {
      'isomorphic-fetch': path.join(__dirname, 'node_modules', 'isomorphic-fetch')
    }
  }

Author: Fantashit

1 thought on “npm linked modules resolve ProvidePlugin dependencies wrong

  1. The provided module resolves relative to the injected file.

      plugins: [
        new webpack.ProvidePlugin({
          fetch: path.join(__dirname, 'node_modules', 'isomorphic-fetch')
        })
      ]

Comments are closed.