docs: absolue imports
See original GitHub issueSummary
Currently the docs recommend to set absolute imports within webpack. While this does work it only applies to webpack. If you are trying to eject from gatsby’s eslint rules or use other tools they will not know how to resolve these and will complain. For those using yarn 1 or 2 there is a better way:
the best practice is to set them in your package.json:
{
"dependencies": {
"hooks": "link:./src/hooks",
}
}
I read this some where more authoritative but can’t find where (yarn docs I believe), I’ll keep looking and update this if I find the link.
https://yarnpkg.com/features/protocols
Motivation
This allows all tools to resolve these paths and preps you for yarn pnp.
Steps to resolve this issue
Draft the doc
- Update the doc, following the format listed in these resources:
- Overview on contributing to documentation
- Docs Templates
- Example of a similar article
Open a pull request
- Open a pull request with your work including the words “closes #[this issue’s number]” in the pull request description
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (10 by maintainers)
Top Results From Across the Web
Advanced Features: Absolute Imports and Module Path Aliases
Configure module path aliases that allow you to remap certain import paths. ... a common pattern is aliasing certain directories to use absolute...
Read more >Absolute vs Relative Imports in Python
An absolute import specifies the resource to be imported using its full path from the project's root folder. Syntax and Practical Examples. Let's...
Read more >Making Life Easier with Absolute Imports - React in Javascript ...
According to create-react-app Docs, We can use absolute imports in our react project by configuring a jsconfig.json / tsconfig.json (for ...
Read more >MarcoGorelli/absolufy-imports: Automatically convert ... - GitHub
A tool and pre-commit hook to automatically convert relative imports to absolute.
Read more >Absolute Imports | jest-preset-angular - GitHub Pages
TypeScript supports absolute imports. The preset (starting from v3.0.0) by default understands absolute imports referring to src, app, ...
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
Thanks @moonmeister, this shows how broken the ecosystem is, and Rome is being built.
I do feel your pain. I mostly use
https://github.com/tleunen/eslint-import-resolver-babel-module
which also tells me how to configure eslint, and because of babel, webpack has the right config as well. I haven’t thought oflink:
before so TIL 😃. The problem with link as stated above its yarn only and we still have to tell babel to transpile `node_modules/hooks, as stated in our docs https://github.com/gatsbyjs/gatsby/blob/master/docs/docs/add-custom-webpack-config.md#modifying-the-babel-loaderWhat if we keep things as is but add a section about “yarn” + “link” and using multiple tools like eslint/typescript/… We don’t want to advocate yarn too much but If it’s a small section, I think it’s okay.
Go for it! Thanks! Ping me when you open the PR and I’ll give it a look.