Can't read property of undefined (mix.initialize() )when use node_modules/.bin/webpack

杀马特。学长 韩版系。学妹 提交于 2019-12-06 04:23:06

In the latest version of laravel-mix you don't need require mix property. According library documentation you just need in webpack.mix.js file:

let mix = require('laravel-mix');

Also in package.json in section scripts you should have path to your vendor file with laravel-mix (if you don't need custom config), for example:

  "scripts": {
     "dev": "webpack --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },

Well, finally i do it.

In video he remove some package of package.json at the beginning. (laravel-mix included) and after this he install laravel-mix 0.3 version.

So when i create the laravel project i don't remove laravel-mix (the version is "0.*". If i do that and i run npm run dev always is good.

I can't understand why he remove package and install it before, and do

cp -r node_modules/laravel-mix/setup/** ./

Hope that's usefull to somebody.

I was following the same video. Here are the steps I took to get past this same error:

  1. $laravel new stream --dev
  2. $cd stream
  3. $npm install
  4. $npm install babel-loader sass-loader vue-loader --save-dev
  5. $cp node_modules/laravel-mix/setup/webpack.config.js ./
  6. Open up ./webpack.config.js and make it look like this:

    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();
    
  7. $node_modules/.bin/webpack

  8. Pick it up around 1:32 in the video

I'm running into more issues in the video as well. If I find solutions to those, I'll update this answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!