Search code examples
node.jswebpackpnpm

Module not found: Error: Can't resolve '***' with pnpm


After I removed 'shamefully-hoist=true' in .npmrc. pnpm throws several errors when webpack is building. After research, I found out that webpack will search modules under different levels of node_modules. The program is using pnpm and all the modules are moved under root/node_modules/.pnpm/node_modules, so webpack can't find the right path of modules and throws errors.

I use two solutions in webpack config to fix this.

solution1: add these modules in

resolve: {
  fallback: {
    ***: false // or require.resolve('buffer')
  }
}

solution2: add modules

modules: ['node_modules/.pnpm/node_modules']

These two solutions can both fix this issue. After reading some issues from github, I still don't know why webpack can't resolve these modules.


Solution

  • Fix this issue when config webpack

    resolve: {
      symlinks: true //default value
    }