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.

Absolute imports do not work when Yarn PnP is enabled

See original GitHub issue

I created a React App using create-react-app with PnP enabled.

npx create-react-app pnp --use-pnp

Then following the documentation, I created a jsconfig.json file to enable absolute imports.

  "compilerOptions": {
    "baseUrl": "src"
  "include": ["src"]

When I use absolute imports, the compiler fails to resolve those. Changing the imports to have relative paths work. Just to see whether this is PnP related, I deleted the ‘.pnp.js’ file and removed the relevant config from package.json as well. Then it worked fine. So I assume this is PnP related.

Environment: create-react-app v3.2.0 on Mac OS X Catalina

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

Gallevycommented, Jan 26, 2020

Any update on this? main breaking point for upgrade to yarn berry

yohanliyanagecommented, Dec 29, 2019

@hlian Thanks for the confirmation and sharing the related issue with regards to Typescript. However, I see this issue with regular JavaScript as well. It seems yarnpkg/berry#589 is Typescript specific.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create-react-app absolute imports don't work with yarn v2 ...
I want to enable absolute imports within the frontend app, so I can do things like import Button from 'components/Button' instead of import ......
Read more >
Imports not properly resolved when using Yarn workspaces ...
All absolute imports that rely on types export resolve in such a way that usages are not captured, even though quick docs are...
Read more >
Migration | Yarn - Package Manager
A step-by-step and in-depth migration guide from Yarn 1 (Classic) to Yarn 2 (Berry).
Read more >
Configuring Jest
Here is how to enable it globally (additional options are not supported):. JavaScript; TypeScript. /** @type {import('jest').Config} */
Read more >
Clean Up Your Imports using Absolute Imports & Alias on ...
I imagine you're using CRA? Our issue almost certainly has to do with the recommended webpack config to enable absolute imports. One of...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found