What is the line throwing the error? Is it in app.js?
Sep 17, 2022
25
Level 17
Adding jQuery to Laravel 9 vite is a pain
Hi i have searched a lot but still have the err
dashboard:184 Uncaught ReferenceError: $ is not defined
this what I have tried vite.config
export default defineConfig({
plugins: [
laravel({
input: ["resources/css/app.css", "resources/js/app.js"],
refresh: true,
}),
],
resolve: {
alias: {
$: "jQuery",
},
},
});
app.js
import jQuery from "jquery";
window.$ = window.jQuery = jQuery;
and I have this in app.blade.php
<!-- Scripts -->
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
and ofcourse
npm run dev
Level 122
@lifesound download the minified jquery file and load it from a local public folder. Pretend you never heard of vite. No build step is required.
2 likes
Please or to participate in this conversation.