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

Test fails using yarn@berry and pnp-webpack-plugin #10053

Closed
irudoy opened this issue May 16, 2020 · 12 comments · Fixed by #10383
Closed

Test fails using yarn@berry and pnp-webpack-plugin #10053

irudoy opened this issue May 16, 2020 · 12 comments · Fixed by #10383

Comments

@irudoy
Copy link
Contributor

irudoy commented May 16, 2020

🐛 Bug Report

Testing webpack build with babel-jest fails using yarn@berry and pnp-webpack-plugin.

test.js

const webpack = require('webpack');

test('simple', () => {
    expect(
        webpack({
            resolve: {
                plugins: [require('pnp-webpack-plugin')],
            },
        })
    ).not.toThrow();
});

output

    The whole PnP file got strict-mode-ified, which is known to break (Emscripten libraries aren't strict mode). This usually happens when the file goes through Babel.

       5 |   Object.freeze({}).detectStrictMode = true;
       6 | } catch (error) {
    >  7 |   throw new Error(`The whole PnP file got strict-mode-ified, which is known to break (Emscripten libraries aren't strict mode). This usually happens when the file goes through Babel.`);
         |         ^
       8 | }
       9 |
      10 | var __non_webpack_module__ = module;

      at Object.<anonymous> (.pnp.js:7:9)
      at Object.<anonymous> (index.test.js:7:27)

To Reproduce

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

Expected behavior

The test is successfully passed.

Link to repl or repo (highly encouraged)

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

envinfo

  System:
    OS: macOS 10.15.4
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Binaries:
    Node: 14.2.0 - /usr/local/bin/node
    Yarn: 2.0.0-rc.33 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm
@irudoy
Copy link
Contributor Author

irudoy commented Aug 7, 2020

there was a workaround for webpack@4

resolve: {
  plugins: IS_TEST ? [] : [require('pnp-webpack-plugin')],
},

but webpack@5 supports yarn pnp by default, so it's not working anymore

@SimenB
Copy link
Member

SimenB commented Aug 7, 2020

@arcanis any ideas?

@arcanis
Copy link
Contributor

arcanis commented Aug 7, 2020

Can't check right now, but I suspect babel-jest is transpiling the .pnp.js file, which it shouldn't do for the reason described in the error message. I'd suggest to try disabling transforms on this file.

@SimenB
Copy link
Member

SimenB commented Aug 7, 2020

Interesting! Our current default transformIgnorePatterns is just node_modules - should we add .pnp.js as well?

@arcanis
Copy link
Contributor

arcanis commented Aug 7, 2020

That would be ideal! In fact, if you can ignore .pnp.* it would probably be the best - we'll likely change the file name to .pnp.cjs in the next major, otherwise it causes problem with projects configured for ESM.

@SimenB
Copy link
Member

SimenB commented Aug 7, 2020

@irudoy can you confirm adding .pnp.js to transformIgnorePatterns fixes the issue?

@irudoy
Copy link
Contributor Author

irudoy commented Aug 7, 2020

Adding .pnp.js to transformIgnorePatterns fixes the issue, but only for webpack 4. For webpack 5 it didn't work, and it still throws.

@arcanis
Copy link
Contributor

arcanis commented Aug 7, 2020

Curious - afaik Webpack 5 also simply requires pnpapi, I don't know why it would still be transpiled 🤔

@irudoy
Copy link
Contributor Author

irudoy commented Aug 8, 2020

I'm sorry for the misinformation. Definitely, it's working just fine with webpack 5! It was late at night, and I missed something.

Big thanks for finding a solution 😸

@SimenB this should be added to the default value of transformIgnorePatterns, I guess?

@SimenB
Copy link
Member

SimenB commented Aug 8, 2020

Yeah, let's do it. Wanna send a PR?

@irudoy
Copy link
Contributor Author

irudoy commented Aug 8, 2020

done

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants