简体   繁体   English

Laravel InertiaJS SSR:找不到模块 laravel-vite-plugin/inertia-helpers.js

[英]Laravel InertiaJS SSR: Cannot find module laravel-vite-plugin/inertia-helpers.js

I have installed the newest version of Laravel as of this writing with Sail.在撰写本文时,我已经使用 Sail 安装了最新版本的 Laravel。 I use Inertia for the front end.我在前端使用惯性。 I followed the guide and installed the necessary dependencies.我按照指南安装了必要的依赖项。 Running npm run dev and npm run build works fine.运行npm run devnpm run build工作正常。 However, when I run npm run ssr I encountered the follwing error:但是,当我运行npm run ssr时,我遇到了以下错误:

Cannot find module '/var/www/html/node_modules/laravel-vite-plugin/inertia-helpers.js' imported from /var/www/html/bootstrap/ssr/ssr.mjs

package.json package.json

{
    "private": true,
    "scripts": {
        "dev": "vite",
        "build": "vite build && vite build --ssr",
        "ssr": "node bootstrap/ssr/ssr.mjs"
    },
    "devDependencies": {
        "@inertiajs/inertia": "^0.11.0",
        "@inertiajs/inertia-vue3": "^0.6.0",
        "@inertiajs/progress": "^0.2.7",
        "@inertiajs/server": "^0.1.0",
        "@vitejs/plugin-vue": "^3.0.1",
        "@vue/server-renderer": "^3.2.37",
        "autoprefixer": "^10.4.7",
        "axios": "^0.27",
        "laravel-vite-plugin": "^0.5.0",
        "lodash": "^4.17.19",
        "postcss": "^8.4.14",
        "tailwindcss": "^3.1.6",
        "vite": "^3.0.0",
        "vue": "^3.2.37"
    }
}

resources/js/ssr.js资源/js/ssr.js

import { createInertiaApp } from '@inertiajs/inertia-vue3';
import createServer from '@inertiajs/server';
import { renderToString } from '@vue/server-renderer';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { createSSRApp, h } from 'vue';

createServer(page =>
  createInertiaApp({
    page,
    render: renderToString,
    resolve: name => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
    setup({ app, props, plugin }) {
      return createSSRApp({ render: () => h(app, props) }).use(plugin);
    },
  })
);

vite.config.js vite.config.js

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

export default defineConfig({
  plugins: [
    laravel({
      input: 'resources/js/app.js',
      refresh: true,
      ssr: 'resources/js/ssr.js',
    }),
    vue({
      template: {
        transformAssetUrls: {
          base: null,
          includeAbsolute: false,
        },
      },
    }),
  ],
  resolve: {
    alias: {
      '@': '/resources/js',
    },
  },
  ssr: {
    noExternal: ['@inertiajs/server'],
  },
});

I will really appreciate someone can point me to the right direction.我真的很感激有人能指出我正确的方向。 I did try to resolve it on my own but no luck.我确实尝试过自己解决它,但没有运气。 I can't find any solution either in the documentation.我在文档中也找不到任何解决方案。

You should modify "ssr": "node bootstrap/ssr/ssr.mjs" to the correct path to ssr.js bundle like "ssr": "node storage/ssr/ssr.js"您应该将 "ssr": "node bootstrap/ssr/ssr.mjs" 修改为 ssr.js 包的正确路径,例如 "ssr": "node storage/ssr/ssr.js"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Tailwindcss 和 laravel-vite-plugin 构建单独的 CSS 文件 - Build separate CSS files using Tailwindcss and laravel-vite-plugin 无法在模块外使用import语句laravel vue惯性ssr - Cannot use import statement outside a module laravel vue inertia ssr 带有 Laravel 和 Vue2 的 InertiaJS:无法重新定义属性:$inertia - InertiaJS with Laravel & Vue2: Cannot redefine property: $inertia 错误:将 vue.js 安装到 Laravel 项目时找不到模块 'C:\vite\bin\vite.js' - Error: Cannot find module 'C:\vite\bin\vite.js' when installing vue.js to Laravel project Laravel 9 Inertiajs Vite 不在共享主机上加载资产 - Laravel 9 Inertiajs Vite not loading assets on Shared hosting Laravel 8 (Inertia js) - 获取 Vue 错误'app.js:30559 [Vue 警告]:创建钩子中的错误:“错误:找不到模块...” - Laravel 8 (Inertia js) - Getting Vue error 'app.js:30559 [Vue warn]: Error in created hook: "Error: Cannot find module...' 路线未定义,laravel微风惯性反应SSR - Route is not defined, laravel breeze inertia react SSR 如何在服务器上部署带有 Inertia SSR 的 Laravel Inertia 应用程序 - How deploy Laravel Inertia app with Inertia SSR on server Laravel + 惯性 + Vite 中的默认持久布局 - Default Persistent Layout In Laravel + Inertia + Vite Laravel/Vite/Inertiajs - 从页面/子文件夹导入自定义页面 - Laravel/Vite/Inertiajs - custom page import from Pages/subfolders
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM