![](/img/trans.png)
[英]Build separate CSS files using Tailwindcss and laravel-vite-plugin
[英]Laravel InertiaJS SSR: Cannot find module laravel-vite-plugin/inertia-helpers.js
在撰寫本文時,我已經使用 Sail 安裝了最新版本的 Laravel。 我在前端使用慣性。 我按照指南安裝了必要的依賴項。 運行npm run dev
和npm 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.