Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

elasticsteve's avatar

Can't get Laravel Mix to work - Frustration LIMIT reached

There should be a MIx category to "Pick a Channel" here in the forum, no? Anyway that's beside the point...

Upgraded Laravel 5.3 to 5.4 in less than an hour. Then began with the Elixir to Mix transition and it was nothing but a nightmare. Spent 4 hours already with what should be a trivial task! I'm exhausted and ready to give up!

First: I use UIkit and have a copy of UIkit (that I tweaked) in resources/assets/uikit.

 mix.js([ // will become all.js
        'resources/assets/js/app.js',
        'resources/assets/uikit/js/uikit.js',
        'resources/assets/uikit/js/components/grid.js'
    ], 'public/js/all.js')

I got an error when running npm run dev that UIKIT is missing and not in the node_modules folder! What? Why is it all of sudden looking there? Yes, grid.js uses UIkit as a dependency, but doesn't care about node_modules or where it is.

I couldn't get it to work and had to move a copy of uikit.js to node_modules which makes no sense to have it twice now.

At least I managed to get it to work, but the thing that is killing me now is that I can't compile a simple scss file! Just can't get it to work even if the scss is empty.

mix.js('resources/assets/js/app.js', 'public/js/all.js')
    .sass('resources/assets/sass/test.scss', 'public/css/main.css');

And then I get:

 ERROR  Failed to compile with 3 errors

 error  in ./resources/assets/sass/test.scss

Module build failed: Error: ENOENT: no such file or directory, scandir 'G:\Dropbox\PhpStorm Projects\elasticstage\node_modules\node-sass\vendor'
    at Error (native)

I don't have a vendor directory in node-sass!

 error 

G:\Dropbox\PhpStorm Projects\elasticstage\node_modules\extract-text-webpack-plugin\loader.js?{"id":1,"omit":1,"remove":true}!G:\Dropbox\PhpStorm Projects\elast
icstage\node_modules\style-loader\index.js!G:\Dropbox\PhpStorm Projects\elasticstage\node_modules\css-loader\index.js!G:\Dropbox\PhpStorm Projects\elasticstage
\node_modules\postcss-loader\index.js!G:\Dropbox\PhpStorm Projects\elasticstage\node_modules\resolve-url-loader\index.js!G:\Dropbox\PhpStorm Projects\elasticst
age\node_modules\sass-loader\index.js?sourceMap&precision=8!G:\Dropbox\PhpStorm Projects\elasticstage\resources\assets\sass\test.scss doesn't export content

...

     Asset      Size  Chunks                    Chunk Names
       /js/all.js   1.49 MB       0  [emitted]  [big]  /js/all
mix-manifest.json  32 bytes          [emitted]

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Steve Rhodes\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
npm ERR! node v6.9.4
npm ERR! npm  v3.10.7
npm ERR! code ELIFECYCLE
npm ERR! @ dev: `node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_
modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 2
npm ERR!

No idea what that could even mean...

And then there is this lovely error message notification in the bottom right corner. I'm really missing the simple to read Elixir errors!

Laravel Mix
Error: !!./../../../node_modules/css-
loader/index.js!./../../../node_modules/
postcss-loader/index.js!./../../../
node_modules/resolve-url-loader/inde
toast

what the hell?? :)

0 likes
19 replies
JeffreyWay's avatar

"I got an error when running npm run dev that UIKIT is missing and not in the node_modules folder! What? Why is it all of sudden looking there? "

It's looking there because it can't find it locally, so it's now checking for an installed dependency. We'll need to see your JS files to know more. I'm guessing that you're not importing your UIKIT module properly.

"I don't have a vendor directory in node-sass!"

Are you sure you have node-sass installed? Try a fresh re-install.

Also, create threads like this on the Mix GitHub repo, so that we can actually help you.

http://github.com/jeffreyway/laravel-mix

elasticsteve's avatar

I just installed nodejs. Do I need something else? I read the docs on Laravel.com and it didn't mention node-sass.

I'll move over to GitHub. Thanks.

JeffreyWay's avatar

You shouldn't need to, because it's included in the sass-loader dependency that Mix has.

My guess is that something went wonky when you installed all of your Node dependencies. I'd do a rm -rf node_modules and then npm install from scratch.

elasticsteve's avatar

I already did that earlier today! I'm on Windows BTW. And I have the node-sass folder, but just no vendor folder inside. And I did use: npm install --no-bin-links

Probably unreleated, but when I run this I get:

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Steve Rhodes\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install" "--no-bin-links"
npm ERR! node v6.9.4
npm ERR! npm  v3.10.7

npm ERR! Maximum call stack size exceeded

When I run it again, it finishes with no errors, though. You think: Is anything working? haha

elasticsteve's avatar

I read this on GitHub.

I then ran:

node node_modules/node-sass/scripts/install.js followed by npm rebuild node-sass

which created the vendor directory. Now the Sass compiles!

The other problem with js still persists (without using node_modules).

mix.js([ // will become all.js
        'resources/assets/js/app.js',
        'resources/assets/uikit/js/uikit.js',
        'resources/assets/uikit/js/components/grid.js'
    ], 'public/js/all.js');

uikit.js alone compiles with no errors.

When I add grid.js I get errors, because it looks for uikit in node_modules.

We already know the uikit.js is there because it compiled fine without the component! But later when we add grid.js, the compiler complains that uikit is not found.

ERROR  Failed to compile with 1 errors

These dependencies were not found in node_modules:

* uikit

I gave up and installed UIkit with npm additionally (although being a perfectionist it bothers me a bit!), but it all compiles.

simondavies's avatar

what does your grid.js look like and how are you calling the uikit.js??

elasticsteve's avatar

The UIkit css framework comes with optional js components. grid.js being one of them.

This is how the beginning of it looks like:

/*! UIkit 2.27.2 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
(function(addon) {

    var component;

    if (window.UIkit) {
        component = addon(UIkit);
    }

    if (typeof define == 'function' && define.amd) {
        define('uikit-grid', ['uikit'], function(){
            return component || addon(UIkit);
        });
    }

})(function(UI){
...

I think it's a bad idea to run all of this through the ES2015 compiler with.js

With Elixir I just concatenated all the UIkit files and only ran the main app.js and vue components through webpack. That worked without a glitch.

I have another js (jquery-visible.js), which also doesn't work anymore. There is a lot of trouble throwing everything into .js. I guess it's better to use .comine for all js files that don't require a ES2015 compiler.

Having said this, now I ran into another problem!

This line:

 .js('resources/assets/js/app.js', 'resources/assets/js/compiled/app.js')

now stores app.js into /public/resources/assets/js/compiled/app.js! Why on earth is is doing that??

I wanted to store it there so I can concatenate it later with other js files. It seems like nothing is doing what I expect! I'm not blaming anyone, but this is not very pleasant...

simondavies's avatar

ok, the last bit is that you will need to edit your public folder settings, but then you cannot compile it then all in to there after wards.

use mix.copy() to move files into there to use later

elasticsteve's avatar

It's looking there because it can't find it locally, so it's now checking for an installed dependency. We'll need to see your JS files to know more. I'm guessing that you're not importing your UIKIT module properly.

Importing? I don't import anything. With Elixir I just concatenated all .js files and that was it. I just has to make sure jquery was before uikit.js and that before the Uikit components. Is this different when using .js with MIX?

elasticsteve's avatar

This is how my gulpfile.js looked for Elixir. You might think it should be pretty easy to convert this to a webpack.mix.js file, but I can't do it... Maybe it's just my stupidity, I don't know...

const elixir = require('laravel-elixir');

require('laravel-elixir-vue-2');

elixir((mix) => {
    // Core elements
    mix.styles([ // will become all.css
        './resources/assets/uikit/css/uikit-edit.css',
        './resources/assets/uikit/css/components/upload.gradient.css',
        './resources/assets/uikit/css/components/sticky.gradient.css',
        './node_modules/sweetalert/dist/sweetalert.css',
        'animate.css',
        'app.css'
    ])
        .webpack('app.js', 'resources/assets/js/compiled/app.js') // default Laravel bootsrap
        .scripts([ // will become all.js
            'compiled/app.js', // Laravel bootstrap
            './resources/assets/uikit/js/uikit.js',
            './resources/assets/uikit/js/components/grid.js',
            './resources/assets/uikit/js/components/notify.js',
            './resources/assets/uikit/js/components/parallaxSteve.js',
            './resources/assets/uikit/js/components/upload.js',
            './resources/assets/uikit/js/components/sticky.js',
            './resources/assets/uikit/js/components/tooltip.js',
            './node_modules/sweetalert/dist/sweetalert.min.js',
            'jquery.visible.js',
            'aurora.js'
        ])

        // Individual loaded elements
        .sass('pages/main.scss')
        .webpack('pages/main.js')
        .webpack('pages/account.js')

        // Fonts
        .copy('resources/assets/uikit/fonts/FontAwesome.otf','public/fonts/FontAwesome.otf')
        .copy('resources/assets/uikit/fonts/fontawesome-webfont.ttf','public/fonts/fontawesome-webfont.ttf')
        .copy('resources/assets/uikit/fonts/fontawesome-webfont.woff','public/fonts/fontawesome-webfont.woff')
        .copy('resources/assets/uikit/fonts/fontawesome-webfont.woff2','public/fonts/fontawesome-webfont.woff2')
        .copy('./resources/assets/fonts/impact label.ttf','public/fonts/impact label.ttf')
});
simondavies's avatar

The grid.js error might because its looking for a global variable window.UIkit, so you would need to load in the UIkit and assign it to the global variable something like this might work, in a bootstrap file loaded first??

window.UIkit = require('uIkit');
elasticsteve's avatar

I guess this is because of the way the new ".js" works, right? Because it's an ES2015 compiler I have to import all the files I add.... Hmmm

Jeffrey should have explained this a bit better in the Laravel 5.4 Mix video for idiots like me. I assumed I can use .js in the same way as I used .scripts in Elixir. Big mistake!

This will take a bit longer to solve I guess...

2 likes
simondavies's avatar

not really, but if you're trying to combine a mix of es6 and normal files then yes.

You could always create to js files one as a bootstrap / libraries file and the other with the components etc, i do this as file size can be large.

Unfortunately, @JefferyWay cannot catch or interoperate all eventualities and as it's a new way, its going to have its bugs, and issues, nothings perfect and not all things can be caught until tested in the public domain.

Without these issues or hurdle's we cannot learn, unfortunately we all go through this frustrating thing with things in life as well as programming etc

We learn by others keep it up :-), im off to bed so other might be able t assist you know sorry.

elasticsteve's avatar

yes, of course. We all learn the hard way! Sometimes the Jeffrey way. :)

cheers

elasticsteve's avatar

ok, I've played around for hours, I can't get anything to work. My app doesn't even see jquery. This is really frustrating...

I ran the standard app.js that comes with Laravel 5.4 and the boostrap.

mix.js('resources/assets/js/app.js', 'public/js')

loaded the app.js script in the blade layout as usual.

and then I get errors like:

all.js:33Uncaught Error: UIkit requires jQuery
    at all.js:33
    at all.js:41
(anonymous) @ all.js:33
(anonymous) @ all.js:41
jquery.js?27d9*:3846 jQuery.Deferred exception: $(...).visible is not a function TypeError: $(...).visible is not a function
    at HTMLDocument.<anonymous> (http://elastic.app/js/main.js:10319:30)
    at mightThrow (http://elastic.app/js/main.js:3643:29)
    at process (http://elastic.app/js/main.js:3711:12) undefined
jQuery.Deferred.exceptionHook @ jquery.js?27d9*:3846
process @ jquery.js?27d9*:3642
main.js:16 Uncaught TypeError: $(...).visible is not a function
    at HTMLDocument.<anonymous> (main.js:16)
    at mightThrow (jquery.js?27d9*:3570)
    at process (jquery.js?27d9*:3638)

I'm worn out! Going to bed...

JeffreyWay's avatar

If you were just concatenating the files with Elixir, then do the same thing with Mix. You can use mix.combine().

elasticsteve's avatar

doesn't work either... more details later... too tired!

elasticsteve's avatar

I now added a lot of requires to the bootstrap.js instead of concatenating all js files like I did in the past.

window._ = require('lodash');

window.$ = window.jQuery = require('jquery');

require('./jquery.visible.js');

import Vue from 'vue';
window.Vue = Vue;

$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

window.UIkit = require('../uikit/js/uikit.js');
    require('../uikit/js/components/grid.js');
    require('../uikit/js/components/notify.js');
    require('../uikit/js/components/parallaxSteve.js');
    require('../uikit/js/components/upload.js');
    require('../uikit/js/components/sticky.js');
    require('../uikit/js/components/tooltip.js');
    require('sweetalert');
    require('./aurora.js');
window.moment = require('moment');

It all works, but now I get TokenMIsmatch Errors when making a jQuery $.ajax and the jquery-visible plugin doesn't recongise jQuery. I posted on GitHub

elasticsteve's avatar

Got it all working! phew! Because .js compiles ES2015, it's best to have everything in one js file and use a lot of requires. In the past I have concatenated several js files, but this won't work here and also was responsible for my TokenMismatch and jQuery plugins not working because of scope issues. The moment I had everything in one js file it worked.

I have to say it all looks a lot cleaner now than in the past. Was a bit painful to adjust (and there were also a few bus with Mix for Windows users that are fixed now) that made it a bit of a nightmare for me, but it was also because I was a bit inexperienced with imports/requires, scope in JS and ES2015.

1 like

Please or to participate in this conversation.