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] absolute imports reported as "Undeclared dependency" by @yarnpkg-doctor

See original GitHub issue

Describe 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:closed
  • Created 4 years ago
  • Reactions:12
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
njjcommented, May 2, 2020

@arcanis Thanks for that. And if we don’t use specific things around the “name” in the package.json. i.e.

import { foo } from 'test-helpers';
import { bar } from 'test-helpers/enzyme';
import { baz } from 'api/v1-client';

What would you recommend?

1reaction
damiangreencommented, Dec 21, 2021

@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 from compilerOptions and the include 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

Read more comments on GitHub >

github_iconTop 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 >

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