[Bug] absolute imports reported as "Undeclared dependency" by @yarnpkg-doctor
See original GitHub issueDescribe the bug
I m using absolute imports as described at https://create-react-app.dev/docs/importing-a-component/#absolute-imports
To Reproduce
Afer running yarn dlx @yarnpkg/doctor
all absolute imports reported “Undeclared dependency”
This is my reproduction case:
const {promises: {writeFile}} = require(`fs`);
const path = require('path');
await yarn(`dlx`, `create-react-app`,`test`)
process.chdir(path.resolve(process.cwd(), 'test'));
await writeFile("jsconfig.json", `
{
{
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}
`)
await writeFile("src/example.js", `
const title = "example import";
export default title;
`)
await writeFile("src/App.jsx", `
import exampleImport from "example";
export default function App() {
return(
<h1>{exampleImport}</h1>
)
}
`)
const output = await yarn(`dlx`,`@yarnpkg/doctor`,`.`);
expect(output).not.toContain('Undeclared dependency on example');
Environment if relevant (please complete the following information):
- OS: [Linux]
- Node version [v12.14.1]
- Yarn version [2.0.0-rc.27]
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:5 (1 by maintainers)
Top Results From Across the Web
yarnpkg-doctor | Yarn API
This rule warns when imported dependencies are not listed in a project/workspace's package.json. Node allows you to import any package without having a...
Read more >JavaScript/TypeScript false positive with absolute imports
Dependencies should be explicitly listed in the package.json file. Importing a module that is not declared as a dependency makes it an implicit ......
Read more >Create-react-app absolute imports don't work with yarn v2 ...
I want to enable absolute imports within the frontend app, ... yarn tsc --noEmit gives an error like this on any absolute import:...
Read more >Why and How to Use Absolute Imports in React
The Problem; Absolute Imports; Using TypeScript; Using JavaScript; For VS Code; For WebStrom / IntelliJ Idea; With ESLint; By Convention ...
Read more >Complete Guide to Imports in Python: Absolute, Relative ...
by Aquiles Carattino Oct. 4, 2019 relative Imports absolute ... When we install packages, they will have dependencies, and very quickly we lose...
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 FreeTop 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
Top GitHub Comments
@arcanis Thanks for that. And if we don’t use specific things around the “name” in the package.json. i.e.
What would you recommend?
@arcanis Can you elaborate a little on what the resolution is. I read the link but it’s not entirely clear. If I understand correctly I shall need to do a batch replace of every absolute import in my package. e.g.
import { useContextValue } from 'components/context/tableContext'
=>import { useContextValue } from 'my-package-name/components/context/tableContext'
Would i need to remove
baseUrl
fromcompilerOptions
and theinclude
array?VSCode import will not automatically add this suffix so for every new import I will need to manually add, which will be a pain