Absolute imports do not work when Yarn PnP is enabled
See original GitHub issueI 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.
https://create-react-app.dev/docs/importing-a-component/#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:
- Created 4 years ago
- Reactions:1
- Comments:11 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Any update on this? main breaking point for upgrade to yarn berry
@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.