question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Test fails using yarn@berry and webpack since v27

See original GitHub issue

🐛 Bug Report

Testing webpack build fails using yarn@berry since jest v27

test.js

const webpack = require('webpack');

test('simple', () => {
    expect(() => {
        webpack({
            entry: './main.js'
        })
    }).not.toThrow();
});

output

expect(received).not.toThrow()

    Error name:    "Error"
    Error message: "Cannot find module 'pnpapi' from '/.../.yarn/cache/enhanced-resolve-npm-5.8.2-b25228f39b-1af3f6bcb9.zip/node_modules/enhanced-resolve/lib'·
    Require stack:
      .yarn/cache/enhanced-resolve-npm-5.8.2-b25228f39b-1af3f6bcb9.zip/node_modules/enhanced-resolve/lib/index.js
      .yarn/$$virtual/webpack-virtual-7b5d4f14ba/0/cache/webpack-npm-5.40.0-421f019ffd-1d13fff8f7.zip/node_modules/webpack/lib/FileSystemInfo.js
      .yarn/$$virtual/webpack-virtual-7b5d4f14ba/0/cache/webpack-npm-5.40.0-421f019ffd-1d13fff8f7.zip/node_modules/webpack/lib/Compilation.js
      .yarn/$$virtual/webpack-virtual-7b5d4f14ba/0/cache/webpack-npm-5.40.0-421f019ffd-1d13fff8f7.zip/node_modules/webpack/lib/Compiler.js
      .yarn/$$virtual/webpack-virtual-7b5d4f14ba/0/cache/webpack-npm-5.40.0-421f019ffd-1d13fff8f7.zip/node_modules/webpack/lib/webpack.js
      .yarn/$$virtual/webpack-virtual-7b5d4f14ba/0/cache/webpack-npm-5.40.0-421f019ffd-1d13fff8f7.zip/node_modules/webpack/lib/index.js
      index.test.js
    "

          at resolveSync (.yarn/cache/resolve-patch-55fcdb097c-c4a515b760.zip/node_modules/resolve/lib/sync.js:102:15)

To Reproduce

https://github.com/irudoy/yarn-berry-webpack-jest-repro/tree/new

Expected behavior

The test is successfully passed.

Link to repl or repo (highly encouraged)

https://github.com/irudoy/yarn-berry-webpack-jest-repro/tree/new – v27 (not working) https://github.com/irudoy/yarn-berry-webpack-jest-repro/tree/new-2 – v26 (working)

envinfo

  System:
    OS: macOS 11.4
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 14.17.0 - /usr/local/bin/node
    Yarn: 2.4.2 - /usr/local/bin/yarn
    npm: 6.14.13 - /usr/local/bin/npm

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
silvenoncommented, Oct 16, 2021

@irudoy I believe simply using jest-pnp-resolver should help you move forward until this is fixed.

0reactions
irudoycommented, Oct 16, 2021

Thanks, @silvenon! This helped as a workaround

Read more comments on GitHub >

github_iconTop Results From Across the Web

Entry Points - webpack
We will show you the ways you can configure the entry property, in addition to explaining why it may be useful to you....
Read more >
Error running Webpack5 with Babel: Cannot find module 'fs ...
Trying to get Babel and Webpack 5 playing nicely together, but I receive the following error: Module build failed (from .
Read more >
Storybook build fails with "Cannot find module 'webpack/lib/util ...
Storybook build fails with "Cannot find module 'webpack/lib/util/makeSerializable.js" after upgrading storybook packages to 6.3.0 #15336.
Read more >
Error Codes | Yarn - Package Manager
Since it currently doesn't, Yarn emits this error when running yarn constraints check . In order to fix it simply run yarn constraints...
Read more >
Using with webpack - Jest
foobar === 'foobar' ). This is pretty handy for React Snapshot Testing. jest.config.js (for CSS Modules). module ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found