Skip to content
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

Failed to resolve import "angular:jit:template:file;./app.component.html" error when plugin is loaded twice and jit is enabled #1288

Open
1 of 2 tasks
yjaaidi opened this issue Aug 21, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@yjaaidi
Copy link
Contributor

yjaaidi commented Aug 21, 2024

Please provide the environment you discovered this bug in.

Running vitest while loading the angular plugin twice in jit mode fails.

import angular from '@analogjs/vite-plugin-angular';

export default defineConfig(({ mode }) => {
  return {
    plugins: [
      angular({jit: true}),
      angular({jit: true})
    ],
    ...
  }
});

This is a black swan edge case that should almost never happen but when it happens it is really hard to debug.
I just spent few hours due to an issue with Nx vitest executor which extracts the plugins from the vite config and gives it back to vitest causing the plugins to be loaded twice 😅

Which area/package is the issue in?

vitest-angular

Description

When @analogjs/vite-plugin-angular is loaded twice in vite config and jit mode is enabled the following error happens:

Error: Failed to resolve import "angular:jit:template:file;./app.component.html" from "src/app/app.component.ts". Does the file exist?

Please provide the exception or error you saw

No response

Other information

This seems to happen because the templateUrl is extracted from the source code instead of the TS output.

const templateUrls = templateUrlsResolver.resolve(code, id);

I guess that this could be fixed by extracting the template URLs from the transformed data:

let data = typescriptResult?.content ?? '';

Please let me know if this fix works for you or do you suggest a better alternative?

I would be willing to submit a PR to fix this issue

  • Yes
  • No
@yjaaidi yjaaidi added the bug Something isn't working label Aug 21, 2024
@brandonroberts
Copy link
Member

If we can reliably extract the template and style URLs from the compiled output, that seems reasonable to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants