Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't resolve 'pnpapi' with webpack 5.4.0 #263

Closed
dstampher opened this issue Nov 14, 2020 · 16 comments
Closed

Can't resolve 'pnpapi' with webpack 5.4.0 #263

dstampher opened this issue Nov 14, 2020 · 16 comments

Comments

@dstampher
Copy link

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.

@sokra
Copy link
Member

sokra commented Nov 15, 2020

Whats in this line? src/js/App.js 2:0-35

@DanielBailey-web
Copy link

DanielBailey-web commented Dec 3, 2020

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...

@RAMKUMARDANE
Copy link

return require("./PnpPlugin").PnpApiImpl

yes it removes the error,

@laibao101
Copy link

webpack 5.16.0
i use webpack to pack webpack into a bundle.js。it has a same problem。

@alexander-akait
Copy link
Member

Somebody can create reproducible test repo?

dlredden pushed a commit to dlredden/enhanced-resolve that referenced this issue Feb 21, 2021
Issue webpack#263 is preventing my company from upgrading to Webpack v5. This was the proposed fix that worked well for us so I created a PR.
@ferdinando-ferreira
Copy link

Somebody can create reproducible test repo?

@alexander-akait : https://github.com/ferdinando-ferreira/enhanced-resolve-pnpapi-bug

git clone https://github.com/ferdinando-ferreira/enhanced-resolve-pnpapi-bug.git enhanced-resolve-pnpapi-bug
cd enhanced-resolve-pnpapi-bug
npm install
npm run build

@barak007
Copy link
Contributor

barak007 commented Apr 18, 2021

this is fixed in master but is not released....f08fe3f @sokra

@zemlanin
Copy link

f08fe3f seems to be released in 5.8.0

@DavidTanner
Copy link

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)

jscheid added a commit to jscheid/enhanced-resolve-263 that referenced this issue Mar 27, 2022
@jscheid
Copy link

jscheid commented Mar 27, 2022

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

@louisscruz
Copy link

I'm currently experiencing the same as @jscheid with the same exact versions of those dependencies.

@louisscruz
Copy link

I've opened #349, which seems to be patching the issue locally for me. There's got to be a better way, but maybe the approach taken in that PR is good enough to provide a workaround for now?

@louisscruz
Copy link

Aha! Things seem to work as expected if require('pnpapi') is changed to require('module').findPnpApi(process.cwd()). The PR has been updated.

@vankop
Copy link
Member

vankop commented Jun 20, 2022

@louisscruz please try latest webpack

@albertyfwu
Copy link

@vankop I'm on the latest webpack (5.73.0) but still seeing this error.

@chinesehemp
Copy link

chinesehemp commented Nov 14, 2022

Hi all, I'm having the same problem. I'm on yarn v1.22.19, webpack 5.73.0, with enhanced-resolve 5.10.0.

node_modules/enhanced-resolve/lib/ResolverFactory.js on line 126 is still reading return require("pnpapi"); // eslint-disable-line node/no-missing-require

Is there a way to fix this without locally hacking my node_modules?

AtofStryker added a commit to cypress-io/cypress that referenced this issue Jul 31, 2023
AtofStryker added a commit to cypress-io/cypress that referenced this issue Aug 1, 2023
AtofStryker added a commit to cypress-io/cypress that referenced this issue Aug 7, 2023
AtofStryker added a commit to cypress-io/cypress that referenced this issue Aug 9, 2023
nagash77 pushed a commit to cypress-io/cypress that referenced this issue Aug 9, 2023
* chore: [run ci] does further prerequisites for webpack 5:
https://webpack.js.org/migrate/5/#make-sure-your-build-has-no-errors-or-warnings
https://webpack.js.org/migrate/5/#make-sure-to-use-mode
https://webpack.js.org/migrate/5/#update-outdated-options
https://webpack.js.org/migrate/5/#test-webpack-5-compatibility
app builds and runs locally. Time to test out in CI and see if buffer or
process need to be polyfilled by the build

* chore: upgrade to webpack 5 and do the bare minimum to get it working

* chore: get @packages/extension working

* chore: add TODOs to finish after webpack 5 update

* chore: update the webpack config for npm/webpack-batteries-included-preprocessor to be webpack 5 compliant

* chore: patch whatwg-url 7.1.0. package 'source-map' uses
whatwg-url@7.1.0 which has a dependency on punycode node expected API.
since punycode is now polyfilled for us implicitly via the punycode npm
package, the API signatures are a bit different
https://github.com/mathiasbynens/punycode.js/blob/main/punycode.js#L101
vs https://nodejs.org/api/punycode.html#punycodeucs2. The patch uses the
punycode npm package expected API and is needed for source maps to work
for cy.origin() dependencies for Cypress.require()

* chore: convert whatwg patch into dev patch as source-map is not installed when building the binary / installing prod dependencies

* chore: only move production level patches into the binary dist directory for yarn install --production

* chore: remove --openssl-legacy-provider code for node versions 17 and over as webpack has been updated to v5

* chore: fix the webpack-batteries-included-preprocessor tests by shimming the correct node globals and built ins

* chore: provide the define plugin and evalDevtoolPlugin again as we need define in order to build the react-dom library correctly in the bundle to not include the development version

* chore: updating v8 snapshot cache

* chore: updating v8 snapshot cache

* chore: updating v8 snapshot cache

* chore: fix the webpack preprocessor not to change promise references under the hood when compiling the first bundle, as it was causing the webpack preprocessor to hang as the reference itself was different

* chore: fix issues from readFile that were caused by Webpack 5 using 'path-browserify'

* chore: update chrome component testing snapshots to match Webpack 5 changes

* chore: fix mismatched snapshots from webpack 5 update

* chore: use Cypress.Buffer instead of Buffer for selectFile system test to avoid having to polyfill Buffer from webpack

* chore: fix system test webpack path that now includes e2e workspace

* chore: patch enhanced-resolve to properly discover the pnp api for the yarn_v3.1.1_pnp_spec.ts system test. see webpack/enhanced-resolve#263 for more details

* chore: set stats to 'none' for experimentalSingleTabMode to prevent different webpack compiled terminal formatting in the snapshot between local and CI.

* chore: fix node built in tests and configure webpack-batteries-included-preprocessor correctly

* chore: fallback to buffer correctly in config, even though there is no impact due to the provide plugin

* Update binary-cleanup.js to exclude added build dependencies for webpack
5 added by webpack-terser-plugin under the hood

* chore: add stream-browserify to webpack preprocessor batteries included as a dep as its used in the config [run ci]

* chore: make sure process and buffer are installed in the CLI for webpack provide

* chore: build cross platform binaries [run ci]

* chore: fix webpack evalDevToolPlugin instantiation [run ci]

* run all binary jobs [run ci]

* chore: updating v8 snapshot cache

* add find-up to the entry points that need to be kept

* chore: updating v8 snapshot cache

* chore: updating v8 snapshot cache

* chore: fix mocha build warnings

* chore: fix STRIPPED_INTEGRITY_TAG import warnings

* chore: add changelog event

---------

Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com>
Co-authored-by: Ryan Manuel <ryanm@cypress.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests