Error installing SweetAlert on Laravel through npm - laravel

When I run $ npm install sweetalert --save-dev
I get
"sweetalert": "^1.1.3"
saved to my package.json
I run $ npm run dev to compile the app.js file with webpack which loads successfully
But when I try to use the module eg
<script>
sweetAlert("Hello world!");
</script>
I get Uncaught ReferenceError: sweetAlert is not defined
I have also tried to reference the js and css files in my header with combinations of "./node_" and "../node_" and "/node_" and so on
<script src="node_modules/sweetalert/dist/sweetalert.min.js"></script>
<link rel="stylesheet" type="text/css" href="node_modules/sweetalert/dist/sweetalert.css">
What am I missing?

Add require('sweetalert') to your app.js file e.g.:
require('./bootstrap');
require('sweetalert');
Then run npm run dev again.
Lastly, just make sure <script src="{{ mix('js/app.js') }}"></script> is above
<script>
sweetAlert("Hello world!");
</script>
NB The above assumes you have not changed the paths/filenames that come out-of-the-box with laravel.
Hope this helps!

Related

Laravel Mix with Bootstrap 4

I have been learning Laravel (8) and have enjoyed working with tailwindcss. That said there are some things I still wish to use Bootstrap for. I am having trouble locating documentation on how to set up bootstrap with laravel mix in laravel 8. More specifically, in the resources/css/app.css file we put the following for tailwind:
#tailwind base;
#tailwind components;
#tailwind utilities;
but Im not sure what would go here for bootstrap.
I noticed older versions of laravel used php artisan ui bootstrap but that is not available in Laravel 8 from what I have seen.
Run: npm install --save-dev bootstrap jquery popper.js
How your webpack.mix.js should look:
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');
How your app.scss should look:
#import '~bootstrap/scss/bootstrap';
How your app.js should look:
window.$ = window.jQuery = require('jquery');
window.Popper = require('popper.js');
require('bootstrap');
This is how you could use generated files in your .blade.php files:
<link rel="stylesheet" href="{{ mix('css/app.css') }}" type="text/css">
<script src="{{ mix('js/app.js') }}"></script>
If you want to customize Bootstrap, copy node_modules/bootstrap/scss/_variables.scss to resources/sass/_variables.scss, change variables you want and change your app.scss to:
#import '~bootstrap/scss/functions';
#import 'variables';
#import '~bootstrap/scss/bootstrap';
You have some helpful documentation on https://getbootstrap.com/docs/4.0/getting-started/webpack/
Laracasts is also quite helpful.
use this steps
npm install bootstrap
npm install #popperjs/core
npm install sass#^1.32
npm install sass-loader
For Bootstrap Sass files, let's create the “scss” folder in /resources and then a new app.scss file in /resources/scss/. Then insert the following line to the /ressources/scss/app.scss file
#import "bootstrap";
For Bootstrap JavaScript, insert the following line to the /resources/js/app.js file :
import "bootstrap";
To compile Bootstrap JavaScript and Sass files with Laravel Mix, you need to edit the /webpack.mix.js file as follows:
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.sass("resources/scss/app.scss", "public/css");
now you can run you command
npm run dev
Now that we have the /public/css/app.css and /public/js/app.js files with Bootstrap included, we can include them on a page (template Blade) via Laravel's asset helper () to use the Bootstrap components
On your Head
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
On your footer
<script src="{{ asset('js/app.js') }}"></script>
now i think he will work enjoy
Seems to be available in Laravel v8.24.0 though.
Be aware that doing this procedure do regenerate the webpack.mix.js.
Steps are:
install laravel ui: composer require laravel/ui
generate scaffolding: php artisan ui bootstrap
optionnaly generate the same for auth: php artisan ui bootstrap --auth
make npm install required packages: npm install
compile assets: npm run dev or npm run production (for development or for production)
Then make sure to have the following in your blade templates:
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">

Laravel 8 - GET http://localhost:8000/css/app.css net::ERR_ABORTED 404 (Not Found)

I can't use the app.css in my application. Every time the server returns following error
GET http://localhost:8000/css/app.css net::ERR_ABORTED 404 (Not Found).
I use a blade page.
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
I tried to use php artisan serve and php -S localhost:8000 -t public and the booth didn't work.
try this before running your project on server make sure to compile laravel-mix
npm install
and then run
npm run dev
your facing the error because app.css not compiled yet
Make sure you compile your css imports properly in resources/css/app.css first. It should look something like this:
// Fonts
#import url('https://fonts.googleapis.com/css?family=Nunito');
// Bootstrap
#import 'bootstrap';
// Font Awesome
#import '#fortawesome/fontawesome-free';
Then, run this on your terminal: npm run dev. This will in turn, compile your app.css in your public/css. If you are making custom css definitions, i suggest using a custom.css and putting it in your public/css folder, and define it BELOW your app.css, like:
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<link href="{{ asset('css/custom.css') }}" rel="stylesheet">
Assets must always be in the public folder so they can be seen by the {{asset ('') }} command.
Use this worked 100%
run this command
npm i vue-loader
then run
npm run dev
you will get your solution .
This the step for installing:
composer require laravel/ui --dev
php artisan ui bootstrap
php artisan ui bootstrap --auth
npm install
npm run dev
If you get an error at this step you can try this:
npm run prod or npm run production

Laravel Mix vue not working and not found css

Here is my step.
php artisan ui vue
npm install
npm run dev
app.blade
webpack
i'm sure the path js/app.js and css/app.css is correct.
but i still got html front,which step am i missing?
try asset()
<link href="{{ asset('css/main.css') }}" rel="stylesheet">
<script`` src="{{ asset('js/app.js') }}"></script>
ref link https://laravel.com/docs/7.x/helpers#method-asset

laravel auth vue tailwindcss and fontawesome error

please some help.
npm run dev gives me an error
ERROR in ./resources/sass/fontawesome_app.scss (./node_modules/css-loader??ref--5-2!./node_modules/postcss-loader/src??postcss0!./node_modules/resolve-url-loader??ref--5-4!./node_modules/sass-loader/dist/cjs.js??ref--5-5!./resources/sass/fontawesome_app.scss)
Module build failed (from ./node_modules/postcss-loader/src/index.js):
Error: Failed to find '~#fortawesome/fontawesome-free/css/all.css'
in [
/var/www/html/resources/sass
]
at /var/www/html/node_modules/postcss-import/lib/resolve-id.js:35:13
# ./resources/sass/fontawesome_app.scss 2:14-265
I have a new laravel installation with auth and vue. First I installed tailwind;
composer require laravel-frontend-presets/tailwindcss --dev
artisan ui tailwindcss --auth
npm install
npm run dev
Tailwind removed some stuff from the laravel project, so now i try to make fontawesome work again. (i had it working before installing tailwindcss)
npm install --save #fortawesome/fontawesome-free
in webpack.mix.js i add
.sass('resources/sass/fontawesome_app.scss', 'public/css')
I created the file resources/sass/fontawesome_app.scss;
// Fonts
#import '~#fortawesome/fontawesome-free/css/all.css';
In the head of my welcome.blade.php;
<!-- Styles -->
<link href="{{ mix('css/app.css') }}" rel="stylesheet">
<link href="{{ mix('css/fontawesome_app.css') }}" rel="stylesheet">
i compiled all code by running;
npm install && npm run dev
And now i got that error. I named the css like that so it doesn't conflict with
the webpack lines tailwind created.
Please some help!
I changed resources/sass/fontawesome_app.scss into this and it gave me no errors anymore;
// Fonts
$fa-font-path: "../webfonts";
#import '~#fortawesome/fontawesome-free/scss/fontawesome.scss';
#import '~#fortawesome/fontawesome-free/scss/solid.scss';
#import '~#fortawesome/fontawesome-free/scss/brands.scss';
#import '~#fortawesome/fontawesome-free/scss/regular.scss';

Issue in window.Echo

I am following this tutorial to implement Pusher in Laravel 5.4
Below were the step by step things done.
composer require pusher/pusher-php-server
npm install --save laravel-echo pusher-js
instantiated the Echo instance in your resources/assets/js/bootstrap.js
Initialized the pusher key in env and in bootstrap.js file.
Finally, I wrote below code in blade.
<script>
debugger;
window.Echo.channel('SendMessageChannel.1')
.listen('.App.Events.SendMessageEvent', (e) => {
console.log(e);
});
</script>
also added <script src="{{ asset('js/app.js') }}"></script> reference in layout.
While debugging, I found that window.Echo is undefined.
Am I missing anything?
Once you install laravel-echo and pusher-js, you need to run npm run dev so that app.js can have those both libraries.

Resources