laravel / vite-plugin

Laravel plugin for Vite.
MIT License
799 stars 151 forks source link

SyntaxError: Named export 'resolvePageComponent' not found #99

Closed HuyPham55 closed 2 years ago

HuyPham55 commented 2 years ago

Description:

After npm run build, running node bootstrap/ssr/ssr.mjs causes the following error. More detail below:

file:////bootstrap/ssr/ssr.mjs:6 import { resolvePageComponent } from "laravel-vite-plugin/inertia-helpers/index.js"; ^^^^^^^^^^^^^^^^^^^^ SyntaxError: Named export 'resolvePageComponent' not found. The requested module 'laravel-vite-plugin/inertia-helpers/index.js' is a CommonJS module, which may not support all module.exports as named exports.

Related documents:

  1. https://laravel.com/docs/9.x/vite#ssr
  2. https://laravel.com/docs/9.x/starter-kits#server-side-rendering

Steps To Reproduce:

Every command and description is described in 2 official URLs above

  1. Install fresh new Laravel project
  2. Install dependencies composer install
  3. Install Laravel Breeze
  4. Run php artisan breeze:install vue --ssr to scaffold authentication with SSR
  5. npm install
  6. npm run build
  7. node bootstrap/ssr/ssr.mjs

Attempt to fix:

I went to \node_modules\laravel-vite-plugin\inertia-helpers\index.js and change from

export async function resolvePageComponent(path, pages) { const page = pages[path]; if (typeof page === 'undefined') { throw new Error(Page not found: ${path}); } return typeof page === 'function' ? page() : page; }

to

exports.resolvePageComponent = function(path, pages) { const page = pages[path]; if (typeof page === 'undefined') { throw new Error(Page not found: ${path}); } return typeof page === 'function' ? page() : page; }

And run step 6-7 again, it works like a charm. There must be syntax problem, or am I missing a step in the process?

If it's a bug, please fix it soon.

timacdonald commented 2 years ago

Duplicate of https://github.com/laravel/vite-plugin/issues/93

This issue will be fixed in the next release. Please see https://github.com/laravel/vite-plugin/issues/93#issuecomment-1189692624 for a interim solution.