Laravel-mix: Uncaught ReferenceError: require is not defined

Created on 5 Oct 2020  路  7Comments  路  Source: JeffreyWay/laravel-mix

somehow require() is not defined

resources/js/app.js

require('./bootstrap.js');

window.Vue = require('vue');

Vue.component( 'ExampleComponent', require('./components/ExampleComponent.vue') );

const app = new Vue({
    el: '#app',
});

webpack.mix.js

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

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css');

node version: 12.18.4
npm version: 6.14.6
laravel-mix: 4.1.4

Any help would be highly appreciated

Most helpful comment

There must be something else going on, because I can't reproduce what you're seeing. I've never seen that error.

It sounds like, somehow, the file being given to the browser hasn't been compiled.

All 7 comments

I'd need more information.

You're on a really old version of Mix, so maybe start by upgrading to at least v5.

I did upgrade laravel-mix to version 5 but same error persists. Just to confirm, this is a Laravel project

Uncaught ReferenceError: require is not defined
at app:1
. error from browser console.

package.json

"devDependencies": {
        "axios": "^0.18",
        "bootstrap": "^4.4.1",
        "cross-env": "^5.1",
        "element-ui": "^2.13.0",
        "jquery": "^3.2",
        "laravel-mix": "^5.0.0",
        "lodash": "^4.17.5",
        "popper.js": "^1.16.1",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.26.3",
        "sass-loader": "^7.1.0",
        "vue": "^2.6.11",
        "vue-template-compiler": "^2.6.11"
    },
    "dependencies": {
        "chart.js": "^2.9.3",
        "laravel-echo": "^1.8.1",
        "pusher-js": "^7.0.0",
        "vue-chartjs": "^3.5.0"
    }

Could you tell me what other information would you need to know?

When are you seeing that require() error? During compilation or when you load the site in the browser?

During loading in the browser, compilation happens without errors

There must be something else going on, because I can't reproduce what you're seeing. I've never seen that error.

It sounds like, somehow, the file being given to the browser hasn't been compiled.

yeah actually it was part of the configuration that sends the wrong file instead of the compiled file to the browser

thanks a lot for your help

did you solve the probleme ? I have the same issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kpilard picture kpilard  路  3Comments

pixieaka picture pixieaka  路  3Comments

jpmurray picture jpmurray  路  3Comments

Micaso picture Micaso  路  3Comments

sdebacker picture sdebacker  路  3Comments