inertiajs / inertia-laravel

The Laravel adapter for Inertia.js.
https://inertiajs.com
MIT License
2.08k stars 234 forks source link

inertia:start-ssr not starting because lodash.js #507

Closed luismabenitez closed 1 year ago

luismabenitez commented 1 year ago

After migrating to L10, get this error on trying to execute the inertia:start-ssr command. Getting this error:

file://.../bootstrap/ssr/ssr.mjs:6
import { throttle } from "lodash";
         ^^^^^^^^
SyntaxError: Named export 'throttle' not found. The requested module 'lodash' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'lodash';
const { throttle } = pkg;

at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)

Node.js v19.6.0

The application compiles perfectly with "vite build && vite build --ssr"

Anybody had this problem before?

toxanski commented 1 year ago

I have the same error with @material-tailwind/react.

file://.../bootstrap/ssr/assets/MaterialTailwind-6c781cfd.mjs:2
import { Button } from "@material-tailwind/react";
         ^^^^^^
SyntaxError: Named export 'Button' not found. The requested module '@material-tailwind/react' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@material-tailwind/react';
const { Button } = pkg;
SergkeiM commented 1 year ago

Hi @luismabenitez @toxanski

This is not related to Inertia JS but more to the 3rd packages that you use,

you need to add them to noExternal https://vitejs.dev/config/ssr-options.html#ssr-noexternal so they are included in SSR build instead of loading them from node_modules during server start.

jessarcher commented 1 year ago

Hey there,

We're closing this issue because it's inactive, already solved, old or not relevant anymore. Feel to open up a new issue if you're still experiencing this problem.