Skip to content

HMR error [plugin:vite:import-analysis] Failed to resolve import #29369

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

Closed
blueiceprj opened this issue Jan 16, 2025 · 9 comments · Fixed by #29373
Closed

HMR error [plugin:vite:import-analysis] Failed to resolve import #29369

blueiceprj opened this issue Jan 16, 2025 · 9 comments · Fixed by #29373

Comments

@blueiceprj
Copy link

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

Yes

Description

HMR is enabled on my project (--hmr). When I change some code on template or ts file getting some like that error. Here details.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

[plugin:vite:import-analysis] Failed to resolve import "./chunk-4JZSMU2G.js" from ".angular/vite-root/..../main.js". Does the file exist?
/........./.angular/vite-root/...../main.js:9:9
7  |  import {
8  |    AuthGuard
9  |  } from "./chunk-4JZSMU2G.js";
   |          ^
10 |  import {
11 |    UserRouteAccessService
    at TransformPluginContext._formatError (file:///......node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:47397:41)
    at TransformPluginContext.error (file:///......./node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:47392:16)
    at normalizeUrl (file:///....../node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:45642:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async file:///...../node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:45761:39
    at async Promise.all (index 2)
    at async TransformPluginContext.transform (file:///...../node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:45688:7)
    at async EnvironmentPluginContainer.transform (file:///..../node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:47223:18)
    at async loadAndTransform (file:///...../node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:41034:27)
    at async viteTransformMiddleware (file:///...../node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js

Please provide the environment you discovered this bug in (run ng version)

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 19.1.1
Node: 22.12.0
Package Manager: npm 11.0.0
OS: darwin x64

Angular: 19.1.1
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                              Version
--------------------------------------------------------------
@angular-devkit/architect            0.1901.1
@angular-devkit/build-angular        19.1.1
@angular-devkit/build-ng-packagr     0.1002.0
@angular-devkit/core                 19.1.1 (cli-only)
@angular-devkit/schematics           19.1.1
@angular/cdk                         19.0.5
@angular/material                    19.0.5
@angular/material-date-fns-adapter   19.0.5
@angular/youtube-player              19.0.5
@schematics/angular                  19.1.1
rxjs                                 7.8.1
typescript                           5.7.3
zone.js                              0.15.0

Anything else?

No response

@alan-agius4 alan-agius4 transferred this issue from angular/angular Jan 16, 2025
@alan-agius4 alan-agius4 changed the title HMR error HMR error [plugin:vite:import-analysis] Failed to resolve import Jan 16, 2025
@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jan 16, 2025

This issue seems to occur when updating a template in a component of a lazy-loaded route, followed by making changes in the TypeScript file of the importer, example app.routes.ts.

The root cause appears to be

// Temporarily ignore JS files until Angular compiler plugin refactor to allow
// bypassing application code bundling for template affecting only changes.
// TODO: Remove once refactor is complete.
if (hasTemplateUpdates && /\.js(?:\.map)?$/.test(file.path)) {
continue;
}

@alan-agius4 alan-agius4 added freq1: low Only reported by a handful of users who observe it rarely and removed freq1: low Only reported by a handful of users who observe it rarely freq2: medium labels Jan 16, 2025
@Deku-nattsu
Copy link

I have a similar issue (the difference is the bundle generates rather than getting an error), after hmr reload, navigating to other lazy loaded routes stops working due to 404 error where it can't find modules files.

@stevenrlp

This comment has been minimized.

@alan-agius4

This comment has been minimized.

@alan-agius4 alan-agius4 marked this as a duplicate of #29379 Jan 17, 2025
@alan-agius4 alan-agius4 marked this as a duplicate of #29388 Jan 17, 2025
@alan-agius4

This comment has been minimized.

@horodyskyiGloby
Copy link

Any ideas ? Same issue.

@stevenrlp
Copy link

Any ideas ? Same issue.

not a fix but I had to disable hmr to remove the issue with:

ng serve --no-hmr

@chiragmer77
Copy link

any idea how to resolve this?

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
6 participants