Webpack can't find (font) dependencies - laravel

NPM/Webpack can't find dependencies with Laravel Mix
These dependencies were not found:
* font-awesome
* ionicons
ERROR in multi lodash jquery bootstrap-sass fastclick jquery-slimscroll admin-lte icheck ionicons font-awesome datatables.net datatables.net-bs
Module not found: Error: Can't resolve 'font-awesome' in 'D:\Laragon'
# multi lodash jquery bootstrap-sass fastclick jquery-slimscroll admin-lte icheck ionicons font-awesome datatables.net datatables.net-bs
More clearly. These are installed (can find them in node_modules) and require location is correct. I'm also using more packages, and these problems are related to, coincidentally, the only fonts in my webpack.
They are available in the package.json and package.json.lock.
Installed trying different methods: firstly npm install and --save-dev, also tried yarn install and yarn add.
My webpack.mix.js:
let 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.webpackConfig({
module: {
loaders: [
{
test: /\.js?/,
exclude: [/node_modules/, /styles/],
loaders: ['babel'],
include: path.join(__dirname, 'src')
},
{
test: /\.scss$/,
loader: 'style!css!resolve-url!sass?sourceMap'
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
}
]
}
});
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
mix.js('resources/assets/js/auth.js', 'public/js')
.sass('resources/assets/sass/auth.scss', 'public/css');
mix.js('resources/assets/js/admin-lte.js', 'public/js')
.sass('resources/assets/sass/admin-lte.scss', 'public/css');
mix.autoload({
jquery: [ '$', 'jQuery', 'jquery'],
DataTable: 'datatables.net-bs'
});
mix.extract([
'lodash', 'jquery', 'bootstrap-sass',
'fastclick', 'jquery-slimscroll', 'admin-lte',
'icheck', 'ionicons', 'font-awesome',
'datatables.net', 'datatables.net-bs'
], 'public/js/vendor.js');
mix.version();
I also tried it without the mix.webpackConfig, adding the config this was a desperate attempt to fix the fonts.
Here is my package.json:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"admin-lte": "^2.4.2",
"axios": "^0.17",
"bootstrap": "^4.0.0",
"cross-env": "^5.1.3",
"datatables.net": "^1.10.16",
"fastclick": "^1.0.6",
"font-awesome": "^4.7.0",
"icheck": "^1.0.2",
"ionicons": "^3.0.0",
"jquery": "^3.3.1",
"jquery-slimscroll": "^1.3.8",
"laravel-mix": "^2.0",
"lodash": "^4.17.4",
"popper.js": "^1.12",
"script-loader": "^0.7.2"
},
"dependencies": {
"bootstrap-sass": "^3.3.7",
"datatables.net-bs": "^1.10.16"
}
}
And in my .scss:
#import '~font-awesome/scss/font-awesome';
Both on Mac and Windows 10

Include Font Awesome into your NPM config
"devDependencies": {
......
......
"font-awesome": "^4.7.0"
}
Run npm update
And then your app.scss include this
// Font Awesome
#import "~font-awesome/scss/font-awesome.scss";
Run npm dev or `npm watch

Getting rid of font-awesome and ionicons from the extract function solves the problem.

Related

Error when compiling in production mode "is not a function" Vue Laravel Mix

I have a Laravel, VueJs, VueRouter, Vuex application using Webpack to compile my assets.
package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"#fortawesome/fontawesome-free": "^5.14.0",
"axios": "^0.18",
"bootstrap": "^4.0.0",
"laravel-mix": "^3.0.0",
"lodash": "^4.17.19",
"popper.js": "^1.12",
"vue": "^2.5.7"
},
"dependencies": {
"#fullcalendar/core": "^5.11.3",
"#fullcalendar/daygrid": "^5.11.3",
"#fullcalendar/interaction": "^5.11.3",
"#fullcalendar/list": "^5.11.3",
"#fullcalendar/timegrid": "^5.11.3",
"#fullcalendar/vue": "^5.11.3",
"ajv": "^6.12.3",
"animate.css": "^3.7.2",
"aos": "^2.3.4",
"apexcharts": "^3.33.0",
"chart.js": "^2.7.3",
"element-ui": "^2.4.8",
"imagemin": "^6.0.0",
"jquery": "^3.4.1",
"moment": "^2.27.0",
"node-sass": "^4.14.1",
"numeral": "^2.0.6",
"simple-keyboard": "^2.29.72",
"toastr": "^2.1.4",
"vue-apexcharts": "^1.6.2",
"vue-chartjs": "^3.4.0",
"vue-data-tables": "^3.4.5",
"vue-router": "^3.5.2",
"vue-touch-keyboard": "^0.3.2",
"vuedraggable": "^2.24.3",
"vuex": "^3.5.1",
"xml-js": "^1.6.11"
}
}
when i build in production mode npm run prod i get the error s is not a function
but if i build in dev like npm run watch or npm run dev i don't get the error.
How can I debug where the error is in the code so I can fix it? It only shows me in the vue.common.prod line.
vue.common.prod.js:11 TypeError: s is not a function
at e (vue.common.prod.js:11:68600)
my file webpack.mix.js
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/js/front/app.js', 'public/js')
.extract(['vue','vuex', 'jquery', 'bootstrap', 'axios', 'element-ui', 'lodash', 'moment', 'popper.js'])
.version();
mix.webpackConfig({
resolve: {
extensions: ['.js', '.json', '.vue'],
alias: {
'#': path.join(__dirname, './resources/js'),
'~': path.join(__dirname, './resources/js/front'),
'##': path.join(__dirname, './modules'),
'#components': path.join(__dirname, './resources/js/components')
}
},
output: {
filename:'[name].js',
chunkFilename: 'js/[name].js',
},
}).sourceMaps()
option 01) :
check the function you wrote
This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute s function that is not initialized or is not initialized correctly. This means that the expression did not return s function object. So you need to understand that what you are trying to achieve is not s feature.
option 02) :
remove node_module and clear cache npm cache clear --force.
after that reinstall node_module by using npm install.
option 03) :
check your imported thing forgot the curly braces in an import statement.

Laravel mix can not share variables between scss and js files

I'm using laravel mix to build and complie my front-end files, and trying to share variables between scss file and js, here is my scss file and app.js file.
variables.scss
$color: '#ffffff';
:export{
color: $color
}
app.js
import variables from './variables.scss'
console.log(variables)
It should print an object {color: '#ffffff'} defined in variables.scss file. But instead It prints out an empty object.
It's a brand new project,
I use laravel new my-project to download laravel.
npm install, npm install sass sass-loader --save-dev to install packages,that's it.
Here is my package.json file:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"axios": "^0.21",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"sass": "^1.43.2",
"sass-loader": "^12.2.0"
}
}
so,what's the problem?
Do you have this in your webpack.config.js?
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'sass-loader']
}
]
}
}

Module not found: Error: Can't resolve 'timers'

i'm trying to install this package https://github.com/shwilliam/vue-scrollin to my laravel + vue project. after compiling with laravel mix, the following error appeared:
Module not found: Error: Can't resolve 'timers' in
'\node_modules\vue-scrollin\dist'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules
by default. This is no longer the case. Verify if you need this module
and configure a polyfill for it. If you want to include a polyfill,
you need to:
- add a fallback 'resolve.fallback: { "timers": require.resolve("timers-browserify") }'
- install 'timers-browserify' If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "timers": false }
I followed the given instructions but it gives me the same errors.
webpack.mix.js
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js').vue()
.sass('resources/css/app.scss', 'public/css/app.css')
.postCss('resources/css/app.css', 'public/css', [
//
])
.webpackConfig(require('./webpack.config'));
webpack.config.js
module.exports = {
resolve: {
fallback: { "timers": require.resolve("timers") }
},
};
package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"#fortawesome/fontawesome-free": "^5.15.3",
"#fortawesome/fontawesome-svg-core": "^1.2.35",
"#fortawesome/free-regular-svg-icons": "^5.15.3",
"#fortawesome/free-solid-svg-icons": "^5.15.3",
"#fortawesome/vue-fontawesome": "^3.0.0-3",
"#vue/compiler-sfc": "^3.0.7",
"axios": "^0.21",
"bulma": "^0.9.2",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"particles.vue3": "^1.3.1",
"postcss": "^8.1.14",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.8",
"sass-loader": "^10.1.1",
"vue": "^3.0.5",
"vue-loader": "^16.1.2",
"vue-router": "^4.0.5",
"vue-scrollin": "^0.1.2",
"timers-browserify": "^2.0.12"
}
}
You almost got it. webpack.config.js should be:
module.exports = {
resolve: {
fallback: { "timers": require.resolve('timers-browserify') }
},
};
Just change the package in the require.resolve() to what the warning suggests.
For anyone who comes here with a polyfills-problem or about to migrate from webpack 4 to 5, here's the PR with a list of removed polyfills

Laravel Mix, TailwindCSS, and PurgeCSS

First time using laravel mix, I'm sure I'm missing something simple.
I have a project where I'm attempting to use Laravel mix to compile tailwindcss and then use purge to remove any unused css.
package.json
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"repository": {
"type": "git",
"url": "git+ssh://*******************.git"
},
"author": "Sean Smith",
"license": "ISC",
"homepage": "**************",
"devDependencies": {
"cross-env": "^5.2.0",
"laravel-mix": "^4.0.16",
"laravel-mix-purgecss": "^4.1.0",
"postcss-easy-import": "^3.0.0",
"postcss-import": "^12.0.1",
"postcss-nested": "^4.1.2",
"postcss-preset-env": "^6.6.0",
"tailwindcss": "^1.0.3"
},
"dependencies": {
"cross-env": "^5.2.0",
"laravel-mix-purgecss": "^4.1.0"
}
}
webpack.mix.js:
// copied from https://gist.github.com/Log1x/8c1d63024cad15cfb05eec495c41a75b
const mix = require('laravel-mix')
require('laravel-mix-purgecss')
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Sage application. By default, we are compiling the Sass file
| for your application, as well as bundling up your JS files.
|
*/
// Public Path
mix.setPublicPath('./public')
// Browsersync
// mix.browserSync('https://example.test')
/**
* Custom PurgeCSS Extractor
* https://github.com/FullHuman/purgecss
* https://github.com/FullHuman/purgecss-webpack-plugin
*/
// Styles
mix.postCss('src/css/styles.css', 'public/assets/css', [
require('postcss-import')(),
require('tailwindcss')('./tailwind.config.js'),
require('postcss-nested')(),
require('postcss-preset-env')(),
]).purgeCss({
enabled: mix.inProduction(),
folders: ['src', 'templates'],
extensions: ['twig','html','js','php', 'vue'],
extractorPattern: [/[a-zA-Z0-9-:_/]+/g],
})
// JavaScript
mix.js('src/js/app.js', 'public/assets/js')
.extract()
// Source maps when not in production.
if (!mix.inProduction()) {
mix.sourceMaps()
}
// Hash and version files in production.
if (mix.inProduction()) {
mix.version()
}
When I run npm run prod everything appears to work correctly. However in the exported styles.css the only styles that are there are from from tailwind/base
styles.css
/* tailwind base; */
#import "tailwindcss/base";
/* tailwind components; */
#import "tailwindcss/components";
/* tailwind utilities; */
#import "tailwindcss/utilities";
/* all shared css here */
#import "./components/shared.css"
None of the classes that are in my templates/index.twig file have been added nor are the styles in ./components/shared.css file.
classes exist in both index.html and shared.css so should not be purged
When I remove purgeCSS the output css file includes everything as expected. However when purge is added in the only output is tailwind/base css.
Please advise.
Here's a screenshot of my directory structure
When you use mix.postCss() or a separate postcss.config.js file, Mix overrides all other PostCSS plugins, including the PurgeCSS instance, added by this plugin.
To work around this issue, include your PostCSS plugins with mix.options()
const mix = require('laravel-mix');
require('laravel-mix-purgecss');
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css')
.options({
postCss: [require('tailwindcss')]
})
.purgeCss({
enabled: mix.inProduction(),
});
Refer https://github.com/spatie/laravel-mix-purgecss for more details.
Can you please show us your tailwind.config.js file ?
The file should contain something like that :
module.exports = {
purge: [
'./vendor/laravel/jetstream/**/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
],
theme: {
extend: {
lineClamp: {
10 :"10",
12 : "12"
},
fontFamily: {
sans: ['Nunito', ...defaultTheme.fontFamily.sans],
},
},
},
variants: {
extend: {
lineClamp : ["hover"],
opacity: ['disabled'],
},
},
plugins: [require("#tailwindcss/line-clamp"), require('#tailwindcss/forms'), require('#tailwindcss/typography')],
};
purge array should contain the file that you would like to be purged.
purge: [
'./vendor/laravel/jetstream/**/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
],
In this exemple above, the command purge will purge the file at the directory /vendor/laravel/jetstream/ and ** mean look at all subfolder under jetstream and finaly the * mean that all file that have .blade.php extension at the jetstream folder and folder should be purged

How to lint SASS/SCSS on Laravel Mix

I have failed to find a solution for this. The only possible outcome I've seen so far is Laravel-Elixir-SCSS-Lint but the current download numbers doesn't indicate me this is the general choice of the public. I did look into the Laravel Mix Extensions page, nothing obvious there either. Never thought there was not going to be a clear option for Laravel Mix having lint SASS/SCSS before with Gulp, Grunt, etc.
Thank you in advance for the help.
Update
After much digging I have come to the following solution, however the linting is not doing a good job and several mistakes are ignored (check console output at the end)
package.json
{
"name": "test",
"version": "1.0.0",
"description": "Description here.",
"main": "index.js",
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "cross-env NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Me",
"license": "ISC",
"devDependencies": {
"aos": "^2.3.4",
"browser-sync": "^2.26.4",
"browser-sync-webpack-plugin": "^2.0.1",
"cross-env": "^5.2.0",
"laravel-mix": "^4.0.15",
"postcss-reporter": "^6.0.1",
"resolve-url-loader": "^3.1.0",
"sass": "^1.19.0",
"sass-loader": "^7.1.0",
"stylelint": "^10.0.1",
"stylelint-config-recommended": "^2.2.0",
"stylelint-order": "^3.0.0",
"stylelint-scss": "^3.6.0",
"vue-template-compiler": "^2.6.10"
}
}
webpack.mix.js
let mix = require('laravel-mix');
if (!mix.inProduction()) {
mix.webpackConfig({
devtool: 'source-map'
})
.sourceMaps()
}
mix
.copy('libraries/jquery-vide/jquery.vide.min.js', 'dist/js/')
.copy('libraries/headroom/headroom.js', 'dist/js/')
.js('src/js/ab2019.js', 'dist/js/')
.js('src/js/ab2019-vide.js', 'dist/js/')
.sass('src/sass/style.scss', 'dist/css/')
.options({
processCssUrls: false, // Process/optimize relative stylesheet url()'s. Set to false, if you don't want them touched.
postCss:[
require("stylelint")({ /* your options */ }),
require("postcss-reporter")({ clearReportedMessages: true })
]
})
.browserSync({
files: "dist/css/style.css"
})
.setPublicPath('dist');
.stylelintrc.json
{
"extends": "stylelint-config-recommended",
"plugins": [
"stylelint-order",
"stylelint-scss"
],
"rules": {
"block-no-empty": true,
"declaration-colon-space-after": "always",
"indentation": [ 2, {
"message": "Please use 2 spaces for indentation. Tabs make The Architect grumpy.",
"severity": "warning"
} ],
"no-descending-specificity": null,
"order/order": [
"declarations"
],
"order/properties-alphabetical-order": true,
"scss/dollar-variable-colon-space-after": "always-single-line"
}
}
style.scss
$x:1;
.test {
color: white;
background: red
}
.foo {}
a {
}
.bar {
color:#4fd;
padding: 10px 0px;
}
console output
$ npm run dev
> test#1.0.0 dev /fake/path
> npm run development
> test#1.0.0 development /fake/path
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
40% building 7/8 modules 1 active ...e/fake/path/src/sass/style.scss
src/sass/style.scss
32:2 ⚠ Expected background to come before color (order/properties-alphabetical-order) [stylelint]
70% building 9/10 modules 1 active ...e/fake/path/src/sass/style.scss
src/sass/style.scss
32:2 ⚠ Expected background to come before color (order/properties-alphabetical-order) [stylelint]
98% after emitting SizeLimitsPlugin
DONE Compiled successfully in 1489ms
If anyone has this problem I managed to make it work like this.
First I installed:
npm install stylelint stylelint-webpack-plugin --save-dev
Then I added this configuration inside webpack.mix.js file
const StylelintPlugin = require('stylelint-webpack-plugin');
mix.webpackConfig({
...
plugins: [
new StylelintPlugin({ // put your config here
configFile: '.stylelintrc', // path to config file
failOnError: false // don't fail on error
})
]
});
Peace

Resources