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.

[Bug] create-react-app/react-scripts test fails to get correct pnpapi

See original GitHub issue
  • I’d be willing to implement a fix

Describe the bug

When using a simple Jest test that does a require(‘pnpapi’), it gets this 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.

To Reproduce

  1. yarn dlx create-react-app my-app
  2. cd my-app/src
  3. Create this test case, in pnpapi.test.js
describe('Pipapi test', () => {
  test('pnpali', async () => {
    const pnpapi = require('pnpapi');
    pnpapi.findPackageLocator();
  });
});
  1. cd …
  2. yarn react-scripts test src/pnpapi.test.js
  3. You will see output similar to this:
 FAIL  src/pnpapi.test.js
  Pipapi test
    ✕ pnpali (290ms)

  ● Pipapi test › pnpali

    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> (src/pnpapi.test.js:4:20)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        2.532s, estimated 3s

Environment if relevant (please complete the following information):

  • OS: [OSX 10.15.6]
  • Node version [12.16.2]
  • Yarn version [2.3.3]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
francisucommented, Oct 20, 2020

Perfect, that fixed the problem. Thanks for your time, patience, and working on yarn 2. I’m really liking it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug] Files outside of workspace cannot require pnpapi #2197
I'd be willing to implement a fix Describe the bug Script dependencies outside the repository have no access to pnpapi, ...
Read more >
PnP API | Yarn - Package Manager
This typically occurs when a package's peer dependency didn't get provided by its direct parent in the dependency tree. The packagePeers field, if...
Read more >
Error: Unable to locate pnpapi ... is controlled by multiple ...
Have some incorrect globalCache settings? What is the expected result? Yarn packages listed in external dependencies and in Settings > Javascript > Libraries....
Read more >
Can't resolve 'pnpapi' with webpack 5.4.0 - Rysolv
I'm still getting this error, but with yarn berry. Cannot find module 'pnpapi' from 'rootDir/.yarn/cache/enhanced-resolve-npm-5.9.2- ...
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