gpt4 book ai didi

javascript - Uncaught ReferenceError : require is not defined at require ('./bootstrap' ) Laravel Mix

转载 作者:搜寻专家 更新时间:2023-11-01 04:39:58 25 4
gpt4 key购买 nike

我已经使用 Laravel Mix 编译了我的样式表和 javascript 文件,代码如下:

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'
});


它提示必需的
Uncaught ReferenceError: require is not defined at app.js:354 ,这是编译后的app.js
我试过:
1- mix.scripts
2- mix.babel(根据文档,这会将任何 ES2015 代码转换为所有浏览器都能理解的原始 JavaScript。)
我在这里缺少什么?

最佳答案

您的节点版本很可能已过时。 Node JS 6 是第一个处理 ES2015 模块的版本。通过运行检查您的节点版本

node -v

如果您使用的是 Ubuntu 16,则需要添加源存储库以拉取更新版本的节点。运行以下命令应该可以让你升级到最新版本

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 中正常编译。

关于javascript - Uncaught ReferenceError : require is not defined at require ('./bootstrap' ) Laravel Mix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42969805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com