I need to make the SSR for my Laravel application, so I chose the plugin "prerender-spa-plugin".
npm install --save-dev html-webpack-plugin prerender-spa-plugin
cp ./node_modules/laravel-mix/setup/webpack.config.js .
Also, I edited my package.json file for a custom production mode
cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=webpack.config.js
Also, I edited my webkpack.config.js previously copied
`
/**
require('./node_modules/laravel-mix/src/index');
require(Mix.paths.mix());
/**
Mix.dispatch('init', Mix);
/**
let WebpackConfig = require('./node_modules/laravel-mix/src/builder/WebpackConfig');
module.exports = new WebpackConfig().build();
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports.plugins.push(
new HtmlWebpackPlugin({
template: Mix.Paths.root('./resources/views/layout/template.blade.php'),
inject: false
})
);
var PrerenderSpaPlugin = require('prerender-spa-plugin');
module.exports.plugins.push(
new PrerenderSpaPlugin(
Mix.output().path,
[ '/' ]
)
);`
But i got this
`
@ production \dir\www\IOTunesDev
cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=webpack.config.js
\dir\www\IOTunesDev\webpack.config.js:32
template: Mix.Paths.root('./resources/views/layout/template.blade.php'),
^
TypeError: Cannot read property 'root' of undefined
at Object.
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at requireConfig (C:\laragon\www\IOTunesDev\node_modules\webpack\bin\convert-argv.js:97:18)
at C:\laragon\www\IOTunesDev\node_modules\webpack\bin\convert-argv.js:104:17
at Array.forEach (
at module.exports (C:\laragon\www\IOTunesDev\node_modules\webpack\bin\convert-argv.js:102:15)
at yargs.parse (C:\laragon\www\IOTunesDev\node_modules\webpack\bin\webpack.js:171:41)
at Object.Yargs.self.parse (C:\laragon\www\IOTunesDev\node_modules\yargs\yargs.js
:533:18)
at Object.
.js:152:7)
at Module._compile (module.js:660:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ production: cross-env NODE_ENV=production node_modules/webpack/bin/webpac
k.js --progress --hide-modules --config=webpack.config.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ production script.
npm ERR! This is probably not a problem with npm. There is likely additional logging
output above.
`
I have the same error.
@RijaAdrian did you find any workaround?
hey, guys I just solved this problem. just replace the following code with yours.
// === (remember to replace your paths in code) ===
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports.plugins.push(
new HtmlWebpackPlugin({
template: Mix.paths.root('your path here'),
inject: false
})
);
// === (remember to replace your paths in code) ===
var PrerenderSpaPlugin = require('prerender-spa-plugin');
module.exports.plugins.push(
new PrerenderSpaPlugin({
staticDir: path.join(__dirname, 'your build folder here'),
routes: [ '/' ]
})
);
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
hey, guys I just solved this problem. just replace the following code with yours.
// === (remember to replace your paths in code) ===
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports.plugins.push(
new HtmlWebpackPlugin({
template: Mix.paths.root('your path here'),
inject: false
})
);
// === (remember to replace your paths in code) ===
var PrerenderSpaPlugin = require('prerender-spa-plugin');
module.exports.plugins.push(
new PrerenderSpaPlugin({
staticDir: path.join(__dirname, 'your build folder here'),
routes: [ '/' ]
})
);