Skip to content

Extensionless static asset files fail with vite:import-analysis error during dev server #32560

Closed

Description

@nizos

Command

serve

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Static asset files with no file extension cause a vite:import-analysis parse error during ng serve. This is the same class of issue as #30798 (which covered html and .br files), but for extensionless files.
The error occurs because the assets middleware in createAngularAssetsMiddleware only serves JS/TS/CSS files directly, other files including extensionless ones are rewritten to @fs/ URLS and forwarded to Vite's transform pipeline. Vite's internal isJSRequest() then treats any URL without a file extension as JavaScript and attempts to parse the binary content.

Minimal Reproduction

  1. Create a new project
    npx @angular/cli@21 new repro --minimal --skip-git && cd repro

  2. Configure an asset directory with an output path. In angular. json, add to the assets array:
    { "glob": "**/*", "input": "src/assets", "output": "/assets" }

  3. Create an extensionless binary asset

    mkdir src/assets
    cp public/favicon.ico src/assets/MyExtensionlessFile
    
  4. Request the file at runtime (In src/app/app.ts):

    import ( Component, inject, onInit } from @angular/core';
    import (HttpClient) from "@angular/common/http';
    
    @Component({
      selector: 'app-root',
      template: '<p>Check the terminal for the vite:import-analysis error.</p>',
    })
    export class App implements OnInit {
      private http = inject(HttpClient);
    
      ngOnInit() {
        this.http.get('/assets/MyExtensionlessFile', { responseType: 'arraybuffer' }).subscribe({
          next: () => console.log('File loaded successfully'),
          error: (err) => console.error('Failed to load file:', err),
        });
      }
    }

    In src/app/app.config.ts, add provideHttpClient() to the providers array.

  5. Serve and open in browser
    ng serve

Expected behavior: The file is served as a binary asset.
Actual behavior: Internal server error.

Exception or Error

[vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.

Your Environment

Angular CLI: 21.1.5
Angular: 21.1.5
Node.js: 22.22.0
Package Manager: npm 10.9.4
Operating System: win32 x64

Anything else relevant?

No response

Activity

  1. added theissue type on Feb 24, 2026
  2. added a commit that references this issue on Feb 24, 2026
    76708a1
  3. self-assigned this
    on Feb 24, 2026
  4. nizos commented on Feb 25, 2026

    @nizos
    Author

    Thanks for the quick action @alan-agius4, much appreciated!

  5. angular-automatic-lock-bot commented on Mar 28, 2026

    @angular-automatic-lock-bot

    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.

  6. locked and limited conversation to collaborators on Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions