Skip to content

Fix unresolved imports - #3186

Closed
joaoantoniocardoso wants to merge 4 commits into
bluerobotics:masterfrom
joaoantoniocardoso:fix-unresolved-imports
Closed

Fix unresolved imports#3186
joaoantoniocardoso wants to merge 4 commits into
bluerobotics:masterfrom
joaoantoniocardoso:fix-unresolved-imports

Conversation

@joaoantoniocardoso

@joaoantoniocardoso joaoantoniocardoso commented Mar 5, 2025

Copy link
Copy Markdown
Member

Solves this:
image

I saw that part of our config came from moving to vite, then I searched for vite projects and saw that they were using eslint-import-resolver-vite. Then I configured it following their docs, and it worked.

As a side quest, I made unresolved imports throw error in build time, and the build failed on the autopilot import part, so I moved it to a runtime fetch (@Williangalvani is this correct?).

Summary by Sourcery

Fixes unresolved imports by configuring eslint to work with vite aliases. Additionally, moves the autopilot import to a runtime fetch to prevent build errors.

@sourcery-ai

sourcery-ai Bot commented Mar 5, 2025

Copy link
Copy Markdown

Reviewer's Guide by Sourcery

This pull request fixes unresolved import issues by configuring ESLint with eslint-import-resolver-vite and dynamically importing the PX4 metadata file. Additionally, Vite aliases were configured to resolve imports using aliases.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Configured ESLint to resolve imports using the eslint-import-resolver-vite plugin.
  • Installed the eslint-import-resolver-vite package.
  • Added a resolver configuration to .eslintrc.js to use the vite config object.
  • Added the import/no-unresolved rule to .eslintrc.js to enforce import resolution.
.eslintrc.js
core/frontend/package.json
Configured Vite to resolve imports using aliases.
  • Added a resolve.alias configuration to vite.config.js to define an alias for the src directory.
core/frontend/vite.config.js
Dynamically import PX4 metadata to prevent build-time errors due to unresolved imports.
  • Replaced the static import of PX4-parameters/master/parameters.json with a dynamic fetch during runtime.
  • Added error handling for the fetch operation to provide more informative error messages.
core/frontend/src/types/autopilot/px4/metadata-fetcher.ts
Removed webpack-env from tsconfig.json.
  • Removed webpack-env from the types array in tsconfig.json.
core/frontend/tsconfig.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@joaoantoniocardoso
joaoantoniocardoso marked this pull request as draft March 5, 2025 16:39

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @joaoantoniocardoso - I've reviewed your changes - here's some feedback:

Overall Comments:

  • It's great that you've addressed the unresolved imports and configured the eslint resolver, but I'm not sure about disabling the eslint rule import/extensions.
  • Consider adding a comment explaining why the autopilot import was moved to a runtime fetch.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

metadata = await fetchPX4MetadataFromBoard()
} catch (e) {
metadata = (await import('@/PX4-parameters/master/parameters.json')).parameters
const response = await fetch('/PX4-parameters/master/parameters.json');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like this path exists on the built code. In order for this to work I think you'd need to move it to /public

The hint was from the IDE showing:

Cannot find type definition file for 'webpack-env'.
  The file is in the program because:
    Entry point of type library 'webpack-env' specified in compilerOptionsts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants