question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Laravel with vercel-php@0.4.0 css/js was not loaded because its MIME type

See original GitHub issue

Question

/css/app.css?id=63d00dfbd8cde5c569e7 was not loaded because its MIME type, “text/html”, is not “text/css”.

Works if upload public/css/ public/js file to vercel. But I want use Composer build in vercel

Here are my config files: Composer scripts:

        "vercel": [
          "@php -v",
          "npm -v",
          "npm install && npm run prod"
        ],

api/assets.php :

<?php
// File: api/assets.php
$queries = array();
parse_str($_SERVER['QUERY_STRING'], $queries);
$file = $queries['file'];

echo require __DIR__ . '/../' . $file;

vercel.json:

{
    "version": 2,
    "functions": {
        "api/assets.php": { "runtime": "vercel-php@0.4.0" },
        "api/index.php": { "runtime": "vercel-php@0.4.0" }
    },
    "routes": [
        {
            "src": "/(css|js)/(.*)",
            "dest": "/api/assets.php?file=public/$1/$2"
        },
        {
            "src": "/(.*)",
            "dest": "/api/index.php"
        }
    ],
...

related:

Composer scripts output not being saved #102

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
robertdrakedenniscommented, Dec 31, 2021

I use the builds options but since it’s technically deprecated I’m not sure how long it will technically last.

    "builds": [
        { "src": "/api/index.php", "use": "vercel-php@0.4.0" },
        { "src": "/public/**", "use": "@vercel/static" }
    ],
    "routes": [
        {
            "src": "/(css|js|vendor|assets|build)/(.*)",
            "dest": "public/$1/$2"
        },
        {
            "src": "/(.*)",
            "dest": "/api/index.php"
        }
    ],
    ```
    
    

Might help you in getting your setup to work
0reactions
f3l1xcommented, Jan 12, 2022

Hi @guoxiangke. There is no way how to detect which composer script you want to run in single deployment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stylesheet not loaded because of MIME type - Stack Overflow
The fastest way to check it is just to try to open the file directly http://localhost:3000/assets/styles/custom-style.css in a new tab. – ...
Read more >
Laravel CSS Not Working |JS Not Working | Assets ... - YouTube
In this video, I'm gonna be talking about Laravel HTTPS configurations. We will be fixing some of the basic problems that occur when...
Read more >
UNsupported stylesheet - Laracasts
Refused to apply style from '' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is...
Read more >
CSS / JavaScript - Laravel Nova
So, you are free to leverage all Tailwind features and classes that are needed by your custom components. # JavaScript. When building custom...
Read more >
MIME Type is being forced to HTML. What's wrong? : r/PHPhelp
Now the file cannot be sourced to webpages because the MIME-type is ... does not and cannot alter the content type from a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found