analog: `Failed to resolve import "angular:jit:template:file;./app.component.html"` error when plugin is loaded twice and jit is enabled
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.
I guess that this could be fixed by extracting the template URLs from the transformed data:
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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 19 (10 by maintainers)
Commits related to this issue
- fix(vite-plugin-angular): skip double transform in JIT mode Closes #1288 — committed to analogjs/analog by brandonroberts 2 years ago
- fix(vite-plugin-angular): resolve JIT external template/style files Closes #1288 — committed to analogjs/analog by brandonroberts 2 years ago
It also says in their docs to point to a non-existent file if you don’t want to load the main config, but that throws an error.
Great to hear. I’ll consider the bug fixed, and we’ll add some notes to the docs about usage of Storybook with Vitest and the configs
Good idea with naming the separate files though in that case
Thanks @pumano. Storybook isn’t supposed to load the config if the
viteConfigPathis set toundefined. Will take a lookLanded a fix. It can be tested in
1.10.2-beta.4