enhanced-resolve: Can't resolve 'pnpapi' with webpack 5.4.0

ERROR in ./node_modules/enhanced-resolve/lib/ResolverFactory.js 118:9-26
Module not found: Error: Can't resolve 'pnpapi' in 'C:\Users\david\Projects\electron-react @ ./node_modules/enhanced-resolve/lib/index.js 10:24-52
 @ ./node_modules/webpack/lib/ResolverFactory.js 8:16-59
 @ ./node_modules/webpack/lib/Compiler.js 25:24-52
 @ ./node_modules/webpack/lib/index.js 114:9-30
 @ ./src/js/App.js 2:0-35
 @ ./src/js/index.js 3:0-24 5:50-53

Here’s my package.json as well

{
  "name": "electron-react",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "watch": "webpack --config webpack.common.js --watch",
    "start": "electron ."
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "electron": "^10.1.5",
    "react": "^17.0.1",
    "react-dom": "^17.0.1"
  },
  "devDependencies": {
    "@babel/core": "^7.12.3",
    "@babel/preset-env": "^7.12.1",
    "@babel/preset-react": "^7.12.5",
    "babel-loader": "^8.2.1",
    "css-loader": "^5.0.1",
    "electron-reload": "^1.5.0",
    "sass": "^1.29.0",
    "sass-loader": "^10.1.0",
    "style-loader": "^2.0.0",
    "webpack": "^5.4.0",
    "webpack-cli": "^4.2.0"
  }
}

From what I’ve heard, pnpapi is built into webpack now, and that might be causing some conflict? I commented out line 118 in lib/ResolverFactory.js and webpack compiles fine after that.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 16 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I stopped getting the aformentioned error by changing

./node_modules/webpack/node_modules/enhanced-resolve/lib/ResolverFactory.js 118:9-26 to return require("./PnpPlugin").PnpApiImpl

I don’t know if this was the correct way to go about this though…

I’m still getting this error, but with yarn berry.

Cannot find module 'pnpapi' from 'rootDir/.yarn/cache/enhanced-resolve-npm-5.9.2-ffd6aeacc7-792b7a01ab.zip/node_modules/enhanced-resolve/lib'

Require stack:
  rootDir/.yarn/cache/enhanced-resolve-npm-5.9.2-ffd6aeacc7-792b7a01ab.zip/node_modules/enhanced-resolve/lib/index.js
  rootDir/.yarn/__virtual__/webpack-virtual-71baba393b/0/cache/webpack-npm-5.70.0-5fea152450-00439884a9.zip/node_modules/webpack/lib/CacheFacade.js
  rootDir/.yarn/__virtual__/webpack-virtual-71baba393b/0/cache/webpack-npm-5.70.0-5fea152450-00439884a9.zip/node_modules/webpack/lib/Compiler.js
  rootDir/.yarn/__virtual__/webpack-virtual-71baba393b/0/cache/webpack-npm-5.70.0-5fea152450-00439884a9.zip/node_modules/webpack/lib/webpack.js
  rootDir/.yarn/__virtual__/webpack-virtual-71baba393b/0/cache/webpack-npm-5.70.0-5fea152450-00439884a9.zip/node_modules/webpack/lib/index.js
  src/index.ts
  test/index.test.ts

  at resolveSync (../../.yarn/cache/resolve-patch-bad885c6ea-c79ecaea36.zip/node_modules/resolve/lib/sync.js:111:15)

Exact same error as @DavidTanner here, using enhanced-resolve 5.9.2, Yarn 3.2.0 and Jest 27.5.1. Repro: https://github.com/jscheid/enhanced-resolve-263