Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

trongio's avatar

npm run dev works build does not -laravel inertia react

Please Help.

when I serve the page if I have npm run dev running it works

if I run npm run build page does not load (no logical errors displayed/saved anywhere).

I also tried with php artisan inertia:start-ssr

there I get errors like:

TypeError: styled.div is not a function
    at file:///home/azael/Documents/GitHub/casatrade/bootstrap/ssr/assets/LanguageDropdwn-CxzE3EZx.js:5:37
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:474:24)
    at async V (file:///home/azael/Documents/GitHub/casatrade/node_modules/@inertiajs/react/dist/index.esm.js:5:1570)
    at async Server.<anonymous> (file:///home/azael/Documents/GitHub/casatrade/node_modules/@inertiajs/core/dist/server.esm.js:1:527)

vite.config.js

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

export default defineConfig({
    plugins: [
        laravel({
            input: 'resources/js/app.jsx',
            ssr: 'resources/js/ssr.jsx',
            refresh: true,
        }),
        react(),
    ],
});

package.json

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

The issue you're encountering seems to be related to the usage of styled-components in your SSR (Server-Side Rendering) setup. The error message TypeError: styled.div is not a function suggests that there might be a problem with how styled-components is being imported or used in your SSR build.

Here are a few steps to troubleshoot and potentially resolve the issue:

  1. Check Import Statements: Ensure that you are importing styled-components correctly in your components. For example:

    import styled from 'styled-components';
    
  2. Ensure Consistent Versions: Make sure that the version of styled-components you are using is compatible with your setup. You can check the version in your package.json:

    "styled-components": "^6.1.12"
    
  3. Update Vite Configuration: Sometimes, the Vite configuration might need adjustments for SSR. Ensure that your vite.config.js is correctly set up for SSR. Here is an example configuration:

    import { defineConfig } from 'vite';
    import laravel from 'laravel-vite-plugin';
    import react from '@vitejs/plugin-react';
    
    export default defineConfig({
        plugins: [
            laravel({
                input: 'resources/js/app.jsx',
                ssr: 'resources/js/ssr.jsx',
                refresh: true,
            }),
            react(),
        ],
        ssr: {
            noExternal: ['styled-components']
        }
    });
    

    The ssr.noExternal option ensures that styled-components is bundled with your SSR build.

  4. Check SSR Entry Point: Ensure that your SSR entry point (resources/js/ssr.jsx) is correctly set up and does not have any issues with imports or usage of styled-components.

  5. Build and Run SSR: After making these changes, try running the build and SSR commands again:

    npm run build
    php artisan inertia:start-ssr
    

If the issue persists, you might want to create a minimal reproducible example and share it on the Laracasts forum or GitHub for further assistance. This will help others to better understand the problem and provide more targeted solutions.

1 like

Please or to participate in this conversation.