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.

[Windows]: Possible entrypoint path mismatch between the manisfest.json and Illuminate/Foundation/Vite.php

See original GitHub issue
  • Laravel Vite Plugin Version: v0.2.1 (latest)
  • Laravel Version: v9.17.0 (after a composer create-project laravel/laravel:dev-vite)
  • Node Version: v16.13.1
  • NPM Version: v8.3.0

Description:

An Unable to locate file in Vite manifest: {$entrypoint} exception may be thrown on Windows caused by a mismatch between the entrypoint path strings stored in manisfest.json and an entry point given to the @vite Blade directive.

Example

Consider the following bare bones Vite config file:

export default defineConfig({
    plugins: [
        laravel([
            'resources/css/app.css',
            'resources/ts/app.ts',
        ]),
    ],
});

And the @vite blade directive usage:

@vite(['resources/css/app.css', 'resources/ts/app.ts'])

This may produce the aforementioned exception.

This is because entrypoint paths in the manifest.json file may follow Windows’ backslash path separator:

{
    "resources/ts/app.ts": {
        "file": "assets/app.e6f6eb1a.js",
        "src": "resources/ts/app.ts",
        "isEntry": true,
    },
    "resources\\css\\app.css": { // <-- backslashes here
        "file": "assets/app.6d9d1460.css",
        "src": "resources\\css\\app.css",
        "isEntry": true
    }
}

But as here the CSS path given to the directive ('resources/css/app.css') uses the regular slash path separator this causes $manifest[$entrypoint] to fail in line 53 of /laravel/framework/blob/vite/src/Illuminate/Foundation/Vite.php.

Note

This only seem to happen for CSS entry paths.

Possible solutions

From what I understand taking a quick look at the source code of each library, the problem could be solved in line 166 by doing something similar to:

const relativeChunkPath = path.relative(resolvedConfig.root, chunk.facadeModuleId).replaceAll('\\', '/');

And on the PHP side:

// ...

$tags = collect();

foreach ($entrypoints as $entrypoint) {
    $entrypoint = str_replace('\\', '/', $entrypoint);

    if (!isset($manifest[$entrypoint])) {
        throw new Exception("Unable to locate file in Vite manifest: {$entrypoint}.");
    }

    // ...
}

Or only on the PHP side:

// ...

if (!isset($manifests[$manifestPath])) {
    // ...

    $manifests[$manifestPath] = collect(json_decode(file_get_contents($manifestPath), true))->flatMap(
        fn(array $value, string $key): array => [str_replace('\\', '/', $key) => $value]
    );
}

// ...

foreach ($entrypoints as $entrypoint) {
    $entrypoint = str_replace('\\', '/', $entrypoint);

    // ...
}

Question:

Which approach would be better suited to be PRed ?

Steps To Reproduce:

  • Have a Windows machine
  • Check out the example scenario given above

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
VicGUTTcommented, Aug 10, 2022

Just dropping by to say Thank you ! @jessarcher for the implementation here and @timacdonald for the upstream PR. Freaking love Open Source ! 💪🏾 ❤️

1reaction
jessarchercommented, Jun 17, 2022

Hey @VicGUTT,

Thanks for reporting this and for your proposed solutions!

I think the right approach would be to wrap the path in Vite’s normalizePath helper:

- import { Plugin, loadEnv, UserConfig, ConfigEnv, Manifest, ResolvedConfig, SSROptions } from 'vite'
+ import { Plugin, loadEnv, UserConfig, ConfigEnv, Manifest, ResolvedConfig, SSROptions, normalizePath } from 'vite'

...

- const relativeChunkPath = path.relative(resolvedConfig.root, chunk.facadeModuleId);
+ const relativeChunkPath = normalizePath(path.relative(resolvedConfig.root, chunk.facadeModuleId));

I’ll give this a try this afternoon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vite manifest not found - Stack Overflow
I tried to solve the problem but nothing work, I need to change the public folder and the sup folder build file place...
Read more >
"Vite manifest not found" on production server ... - Laracasts
When I deploy a Laravel 9 project to production, Laravel replies: Spatie\LaravelIgnition\Exceptions\ViewException: Vite manifest not found at: /var/www/.
Read more >
Backend Integration - Vite
In your Vite config, configure the entry and enable build manifest: ... asset URLs will be resolved using the back-end server URL instead...
Read more >
Plux: A Higher-level Plugin Mechanism Around Python's Entry Point ...
The plux.json file becomes a part of the distribution, s.t., the plugins do not have to be discovered every time your distribution is...
Read more >
Common Data Model metadata: Introducing manifest
The manifest object describes the list of entities in the solution, giving a detailed schema description for each entity, a collection of data ......
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