pmattheew's avatar

Laravel & InertiaJS not compiling

I'm trying to put my app on the cloud for production but I can't build it using the npm run build command. It is throwing the following error in the cli:

@pMattheew ➜ /workspaces/meinsherpa (main) $ npm run build

> build
> vite build

vite v3.2.2 building for production...
✓ 0 modules transformed.
Could not resolve entry module (index.html).
error during build:
Error: Could not resolve entry module (index.html).
    at error (file:///workspaces/meinsherpa/node_modules/rollup/dist/es/shared/rollup.js:1858:30)
    at ModuleLoader.loadEntryModule (file:///workspaces/meinsherpa/node_modules/rollup/dist/es/shared/rollup.js:22175:20)
    at async Promise.all (index 0)

when I return to the first commit of my branch I can compile it running this command, so this is probably a little mess that I did somewhere, but I spent so many hours trying to solve it that my mind is blocked to solve this now, someone can help me with this?

0 likes
11 replies
Sinnbeck's avatar

If it works in the first commit you should be able to find the specific commit relatively easy

pmattheew's avatar

but in my whole repository doesn't exist a index.html file, and it stills compiling 🤔 updating the code, pulling last commits, makes it break

Sinnbeck's avatar

@pmattheew Updating what? And vite does not need an index.html. Maybe show your vite.config.js as a start

pmattheew's avatar

@Sinnbeck alright.

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';

const vitePort = 5173;

/**
 * Checks if any GitPod/Codespaces environment variable
 * is present and returns its Vite port URL; otherwise 
 * returns null.
 *
 * @returns GitPod/Codespaces URL | null
 */
const getCloudEnv = () => {
    const {
        GITPOD_WORKSPACE_URL,
        CODESPACE_NAME,
        GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN,
    } = process.env;
    if (GITPOD_WORKSPACE_URL) {
        return `${vitePort}-${GITPOD_WORKSPACE_URL.substring(
            'https://'.length
        )}`;
    } else if (CODESPACE_NAME) {
        return `${CODESPACE_NAME}-${vitePort}.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}`;
    }
    return null;
};

const server = getCloudEnv()
    ? {
          port: vitePort,
          host: '0.0.0.0',
          hmr: {
              host: getCloudEnv(),
              clientPort: 443,
          },
      }
    : undefined;

export default defineConfig({
    plugins: [
        laravel(['resources/css/app.scss', 'resources/js/app.js']),
        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
    ],
    server,
});

you can see that I created this getCloudEnv() function because I develop using codespaces/gitpod...

Sinnbeck's avatar

@pmattheew ok. So first thing. Try using the default that comes with laravel. Does that fix it?

pmattheew's avatar

@Sinnbeck actually not; I tried commenting the function and the server declaration, also removing the server property of the object... stills throwing 😫

Sinnbeck's avatar

@pmattheew Ok. Then we can rule that out.

And its when comiling locally it fails also I assume?

pmattheew's avatar

@Sinnbeck yes, locally it is throwing the same error... Any suggestion where I could look out that could be the cause of this issue? 🤔

Sinnbeck's avatar

@pmattheew personally I would strip it way down. Make the simplest app.js file you can and test. Or make a new project and see if you can compile that. And copy over your resources

1 like
pmattheew's avatar
pmattheew
OP
Best Answer
Level 1

@Sinnbeck thank you so much for your help! Today with more calm I could examine it closer following your steps and I could find the reason why it was not compiling.

In this project I had to move my vite.config.js to a new folder, vite/vite.config.js, to store some related scripts within, and when running the vite build command it also asks for the config file, but it wasn't being passed in my npm script. I've configured it for my dev server before with vite -c ./vite/vite.config.js but not for my build command. So doing it solved my issue! Thanks!

Please or to participate in this conversation.