简体   繁体   English

尝试使用 Laravel mix / webpack 时出现 JS 错误

[英]JS errors when trying to use Laravel mix / webpack

I have a webpack mix file, which looks like this.我有一个 webpack mix 文件,看起来像这样。

let mix = require('laravel-mix');  
let basePath = 'app/Resources/assets/sass/';  
let jsPath = 'app/Resources/assets/js/';  
mix.setPublicPath('./web');  
mix.browserSync({proxy: 'rooms.test', ghost: false});
   .js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css')
mix.sass(basePath + 'base.scss', 'web/assets_static/css');

mix.combine(['./node_modules/imagesloaded/imagesloaded.pkgd.js',
    './node_modules/jquery/dist/jquery.js',
    './node_modules/slick-carousel/slick/slick.js',
    './node_modules/picturefill/picturefill.js',
    './node_modules/swipebox/src/js/jquery.swipebox.js',
    './node_modules/moment/min/moment.min.js',
    './node_modules/jquery-pjax/jquery.pjax.js',
    jsPath + '/info-pane.js',
    jsPath + '/base.js'], 'web/assets_static/js/base.js');

When I load the page, I get this error.当我加载页面时,出现此错误。

base.js:15708 Uncaught TypeError: Cannot read property 'defaults' of 
undefined
at HTMLDocument.<anonymous> (base.js:15708)
at mightThrow (base.js:3583)
at process (base.js:3651)

The line for this is :这行是:

$.pjax.defaults.timeout = 25000;

...so it appears that the base js file is for some reason not seeing the pjax file - even though it's in the webpack.mix.js. ...所以看起来基本 js 文件由于某种原因没有看到 pjax 文件 - 即使它在 webpack.mix.js 中。

I'm tearing what little hair I have left out at this one - any help gratefully received.我正在撕掉我在这根头发上留下的一点点头发 - 感激地收到任何帮助。 :-). :-)。

Past this code instead.而是通过此代码。 You have an additional slash in the jsPath and basePath check the last two line you are adding another slash to them您在jsPathbasePath有一个额外的斜线,请检查您正在向它们添加另一个斜线的最后两行

let mix = require('laravel-mix');  
let basePath = 'app/Resources/assets/sass';  //you have here an additional slash 
let jsPath = 'app/Resources/assets/js';  //and here to
mix.setPublicPath('./web');  
mix.browserSync({proxy: 'rooms.test', ghost: false});
mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css');
mix.sass(basePath + 'base.scss', 'web/assets_static/css');

mix.combine(['./node_modules/imagesloaded/imagesloaded.pkgd.js',
    './node_modules/jquery/dist/jquery.js',
    './node_modules/slick-carousel/slick/slick.js',
    './node_modules/picturefill/picturefill.js',
    './node_modules/swipebox/src/js/jquery.swipebox.js',
    './node_modules/moment/min/moment.min.js',
    './node_modules/jquery-pjax/jquery.pjax.js',
    jsPath + '/info-pane.js',
    jsPath + '/base.js'], 'web/assets_static/js/base.js');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM