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

responsed Content-Type is set incorrectly when using stylesheet in html file. #252

Closed
beetaa opened this issue May 25, 2020 · 4 comments
Closed

Comments

@beetaa
Copy link

beetaa commented May 25, 2020

Do NOT ignore this template or your issue will have a very high chance to be closed without comment.

css files in <link rel tag responsed as application/javascript

css files in <link rel tag responsed as application/javascript, and the css content can not be loaded in bowser.

It's ok when using 0.15.3, but when using versions above this, the error occurs.

project dir as:
image

html file as:
image

warging info as:
image

responsed info as:
image

Reproduction

Please provide a link to a repo that can reproduce the problem you ran into.

A reproduction is required unless you are absolutely sure that the the problem is obvious and the information you provided is enough for us to understand what the problem is. If a report has only vague description (e.g. just a generic error message) and has no reproduction, it will be closed immediately.

System Info

  • required vite version: 0.16.10
  • required Operating System: win10@2004 + wsl2
  • required Node version: 13.9.0
  • Optional:
    • npm/yarn version: 6.13.7
    • Installed vue version (from yarn.lock or package-lock.json)
    • Installed @vue/compiler-sfc version

Logs (Optional if provided reproduction)

  1. Run vite or vite build with the --debug flag.
  2. Provide the error log here.
@daychongyang
Copy link
Contributor

daychongyang commented May 25, 2020

In development mode, CSS file will be rewritten to a js module that inserts a style.

@underfin
Copy link
Member

Look like it is a bug.I can fix it.But wiil have an confilct with my worked pr.

@beetaa
Copy link
Author

beetaa commented May 25, 2020

@underfin yes, I think so. and please notice the changes at line 51~56 in the commit f6a21b2

image

thank you for your job.

@knekki
Copy link

knekki commented May 25, 2020

A workaround until fixed is to recover it after compilation and reset the MIME type:

configureServer: ({ app }) => {
  app.use(async (ctx, next) => {
    await next();

    // Recover css files after compilation.
    if (ctx.path.endsWith('.css') && ctx.type == 'application/javascript' && ctx.body) {
      ctx.type = 'css';
      ctx.body = ctx.body.substring(ctx.body.indexOf('"')+1, ctx.body.lastIndexOf('"')).replace(/\\n|\\/g, '').trim();
    }
  })
}

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants