Laravel-mix: Mix.Paths.root of undefined

Created on 3 Apr 2018  路  4Comments  路  Source: JeffreyWay/laravel-mix

  • Laravel Mix Version: 1.7.2
  • Node Version : v9.5.0
  • NPM Version : 5.6.0
  • OS: Windows 10

Description:

I need to make the SSR for my Laravel application, so I chose the plugin "prerender-spa-plugin".

Steps To Reproduce:

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

`
/**

  • As our first step, we'll pull in the user's webpack.mix.js
  • file. Based on what the user requests in that file,
  • a generic config object will be constructed for us.
    */

require('./node_modules/laravel-mix/src/index');
require(Mix.paths.mix());

/**

  • Just in case the user needs to hook into this point
  • in the build process, we'll make an announcement.
    */

Mix.dispatch('init', Mix);

/**

  • Now that we know which build tasks are required by the
  • user, we can dynamically create a configuration object
  • for Webpack. And that's all there is to it. Simple!
    */

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. (C:\laragon\www\IOTunesDev\webpack.config.js:32:29)
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. (C:\laragon\www\IOTunesDev\node_modules\webpack\bin\webpack
.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.
`

stale

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: [ '/' ]
})
);

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RomainGoncalves picture RomainGoncalves  路  3Comments

terion-name picture terion-name  路  3Comments

amin101 picture amin101  路  3Comments

Cheddam picture Cheddam  路  3Comments

kpilard picture kpilard  路  3Comments