Skip to content

feat: tolerate module resolution errors on startup #1529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

aleclarson
Copy link
Contributor

Overview

Avoid crashing the dev server if a broken import exists.

Screenshot 2025-03-21 at 13 53 12

Unrelated to this PR: You can see the suggestion to install vite-tsconfig-paths, but as I understand it, WXT doesn't recommend using that package; preferring that the user sets alias in wxt.config.ts instead.

Manual Testing

  1. Introduce a broken import statement
  2. Start the dev server

Copy link

netlify bot commented Mar 21, 2025

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit fdd9eb3
🔍 Latest deploy log https://app.netlify.com/sites/creative-fairy-df92c4/deploys/67f56bc0cd7ac20008be8d69
😎 Deploy Preview https://deploy-preview-1529--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

if (details && details.importer.startsWith('/@fs/')) {
wxt.logger.error(err.message);
wxt.logger.info('Waiting for import specifier to be fixed...');
watchFile = details.importer.slice(5);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't perfect, since the broken import may not be the fault of the importer. For example, it could be a configuration issue with tsconfig.json or something.

But it's not a big deal, IMO, since the developer can restart the dev process or save the importer's file if necessary.

This comment was marked as resolved.

@aleclarson aleclarson force-pushed the feat/module-resolution-errors-1 branch 2 times, most recently from a5b3520 to 9639e7f Compare March 21, 2025 18:32
@aleclarson

This comment was marked as resolved.

@aleclarson
Copy link
Contributor Author

aleclarson commented Mar 21, 2025

Still not ready. Handling the Rollup failed to resolve import error now!

Okay, should be ready for review! @aklinker1

Copy link
Collaborator

@aklinker1 aklinker1 left a comment

Choose a reason for hiding this comment

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

I like the refactor in this PR! Only requested change is to update/add tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like these changes, but we need to update the tests in detect-dev-changes.test.ts. It's a very well tested function with 100% coverage. So we need to add coverage for the two new cases: no build output and error files.

return error.plugin === 'vite:load-fallback' && error.hook === 'load';
}

export function resolveErrorFiles(err: Error): string[] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

And we should definintely add tests for this function. Will be nice to have example errors we can refer to to understand what exactly what is happening better.

@aleclarson aleclarson force-pushed the feat/module-resolution-errors-1 branch from 39d22ad to 6c969eb Compare April 8, 2025 18:01
@aleclarson
Copy link
Contributor Author

@aklinker1 I updated existing tests for detectDevChanges. I wasn't sure what the test for the new errorFiles argument should look like, so I created a stub for you to fill out.

And we should definintely add tests for this function (resolveErrorFiles). Will be nice to have example errors we can refer to to understand what exactly what is happening better.

Do you mean unit tests with dummy errors resembling real ones, or are you asking for integration tests that reproduce the errors using Babel, Rollup, Vite, etc?

@aklinker1
Copy link
Collaborator

Do you mean unit tests with dummy errors resembling real ones, or are you asking for integration tests that reproduce the errors using Babel, Rollup, Vite, etc?

I was just taking about unit tests, but integration tests would probably be better for this.

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