Javascript 未捕获引用错误:未在require(';/bootstrap';)Laravel Mix中定义require
我已经使用Laravel Mix编译了我的样式表和javascript文件,下面给出了代码:Javascript 未捕获引用错误:未在require(';/bootstrap';)Laravel Mix中定义require,javascript,laravel,webpack,laravel-mix,Javascript,Laravel,Webpack,Laravel Mix,我已经使用Laravel Mix编译了我的样式表和javascript文件,下面给出了代码: const { mix } = require('laravel-mix'); /* |-------------------------------------------------------------------------- | Mix Asset Management |--------------------------------------------------------
const { mix } = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
// mix.js('resources/assets/js/app.js', 'public/js')
// .sass('resources/assets/sass/app.scss', 'public/css');
mix.babel([
'public/js/plugins/loaders/pace.min.js',
'resources/assets/js/app.js',
'public/js/plugins/loaders/blockui.min.js',
'public/js/plugins/ui/nicescroll.min.js',
'public/js/plugins/ui/drilldown.js',
'public/js/plugins/ui/fab.min.js',
'public/js/plugins/forms/selects/select2.min.js',
'public/js/plugins/forms/styling/uniform.min.js',
'public/js/plugins/ui/moment/moment.min.js',
'public/js/plugins/ui/fullcalendar/fullcalendar.min.js',
'public/js/core/app.js',
'public/js/pages/user_pages_profile.js',
] , 'public/js/app.js');
mix.styles([
'public/css/icons/icomoon/styles.css',
'resources/assets/sass/app.scss',
'public/css/core.css',
'public/css/components.css',
'public/css/colors.css',
],'public/css/app.css');
下面是我的app.js
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('./bootstrap'); //complains on this line after compilation
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
Vue.component('example', require('./components/Example.vue'));
const app = new Vue({
el: '#app'
});
它抱怨所需的,
未捕获引用错误:app.js:354中未定义require,这是已编译的app.js
我试过:
1-混合脚本
2-mix.babel(根据文档,这将把任何ES2015代码翻译成所有浏览器都能理解的普通JavaScript。)
我在这里遗漏了什么?您的节点版本很可能已过时。Node JS 6是处理ES2015模块的第一个版本。通过运行
node -v
如果您使用的是Ubuntu 16,则需要添加一个源存储库以获取更新版本的node。运行以下命令将使您获得最新版本
cd ~
curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt-get install nodejs
sudo npm update -g npm
sudo ln -s /usr/bin/nodejs /usr/bin/node
现在试着运行npm run dev,一切都应该在Laravel mix中编译好。你能添加你得到的准确错误吗?问题中提到了错误,但现在在描述中也添加了错误。试着使用导入而不是require。对于导入,我必须在bootstrap.js中导出一些东西,对吗?您使用的是Laravel5.4吗?它的节点v7.5.0很奇怪。如果节点7,则应识别require指令。您是否尝试擦除节点_模块并重新运行npm安装?这是一个新安装。让我再做一次,如果这不能解决问题,我会很难堪。曾经有过同样的问题是你在某一点上和节点升级加重新安装修复了它。希望它能起作用!我没有修好它。我使用的是mix.babel而不是mix.js,我试着在webpack.mix.js中同时编写mix.js和mix.babel,然后我进入了未定义的jQuery。