繁体   English   中英

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

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

在撰写本文时,我已经使用 Sail 安装了最新版本的 Laravel。 我在前端使用惯性。 我按照指南安装了必要的依赖项。 运行npm run devnpm run build工作正常。 但是,当我运行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

{
    "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"
    }
}

资源/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

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'],
  },
});

我真的很感激有人能指出我正确的方向。 我确实尝试过自己解决它,但没有运气。 我在文档中也找不到任何解决方案。

您应该将 "ssr": "node bootstrap/ssr/ssr.mjs" 修改为 ssr.js 包的正确路径,例如 "ssr": "node storage/ssr/ssr.js"

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM