I have two different entry points for server.js and client.js.(I'm using vue-server-renderer and laravel-mix) - (my server.js and client.js looks exactly like described here - spatie/laravel-server-side-rendering and if I make static export import Test from '../views/Test'
it works..
If I try importing the route without lazy loading, SSR works:
import Test from "../views/Test";
export const routes = [{
path: '/my-route',
name: "Test",
component: Test,
}]
But if I try lazy-loading, it fails on the SSR:
export const routes = [{
path: '/my-route',
name: "Test"
component: () => import('../views/Test.vue'),
}]
Cannot find module './js/chunks/server/0.js?id=c3384f174123f0848451'
For the () => import('../views/Home.vue)
, client.js works, only server.js doesn't work.
My server.js
:
import renderVueComponentToString from 'vue-server-renderer/basic';
import app from './app';
import {router} from './router/index';
new Promise((resolve, reject) => {
router.push(context.url);
router.onReady(() => {
resolve(app);
}, reject);
})
.then(app => {
renderVueComponentToString(app, (err, res) => {
if (err) throw new Error(err);
dispatch(res);
});
});
The full error is:
The command "/usr/bin/node /home/vagrant/Code/project/storage/app/ssr/1228cfee3f79dc5949bd898950384e53.js" failed Exit Code: 1(General error)
Working directory: /home/vagrant/Code/project/public Output:
================ Error Output: ================ internal/modules/cjs/loader.js:628 throw err; ^
Error: Cannot find module './js/chunks/server/0.js?id=c3384f174123f0848451'
Update
I think I may have an idea why this is happening (I may be wrong):
export const routes = [{
path: '/',
name: "Home",
component: () => import('../views/Home')
}]
with this code, I get an error:
Error: Cannot find module './js/chunks/server/0.js?id=c3384f174123f0848451'
The command "/usr/bin/node /home/vagrant/Code/project/storage/app/ssr/717358e60bfd52035a1e58256cdfbba0.js" failed. Exit Code: 1(General error) Working directory: /home/vagrant/Code/project/public Output: ================ Error Output: ================ internal/modules/cjs/loader.js:628 throw err; ^ Error: Cannot find module './js/chunks/server/0.js?id=c3384f174123f0848451'
Look at the paths:
In my compiled file (which is at public/js
) I have this line:
var chunk = require("./js/chunks/server/" + ({}[chunkId]||chunkId) + ".js?id=" + {"0":"c3384f174123f0848451"}[chunkId] + "");
That seems like a relative path. However the file is actually running in what I specify in the config/ssr.php
- 'temp_path' => storage_path('app/ssr')
- so it cannot find the path.
However, even I change the temp_path
to public_path()
so that it can find the chunk from ./js/chunks/server/
(which is public/js/chunks/server/0.js
), it still throws the same error. Even though the SSR's temp_path is different.
The command "/usr/bin/node /home/vagrant/Code/project/public/3560d8d101faa4bdef316054b14873cc.js" failed. Exit Code: 1(General error) Working directory: /home/vagrant/Code/project/public Output: ================ Error Output: ================ internal/modules/cjs/loader.js:628 throw err; ^ Error: Cannot find module './js/chunks/server/0.js?id=c3384f174123f0848451'
Also if I console.log(_dirname)
in renderVueComponentToString()
it returns me '/'
server.js
code to the OP. But it returns meCannot find module './js/chunks/server/0.js?id=c3384f174123f0848451'
- (btw, your code is for client-entry not server-entry and my problem is at server-entry; client entry works fine) – Pegu