Laravel Mix Critical CSS - criticalCss is not a function - laravel

I have been trying to compile Webpack with laravel-mix, laravel-mix-purgecss, and laravel-mix-criticalcss. But I have been facing issues compiling it with laravel-mix-criticalcss. If I comment the criticalcss in webpack.mix.js, it works fine, but with criticalcss it throws an error. I have upgraded npm and all packages, but whenever I try to compile webpack, it throws this error:
[webpack-cli] TypeError:
mix.js(...).options(...).postCss(...).options(...).sass(...).sass(...).criticalCss
is not a function
I have included laravel-mix-criticalcss in webpack.mix.js
require('laravel-mix-criticalcss');
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"
},
"dependencies": {
"intersection-observer": "^0.12.0",
"laravel-vue-pagination": "^3.0.0",
"sass-migrator": "^1.5.4",
"v-lazy-image": "^2.1.1",
"vanilla-lazyload": "^17.6.1",
"vue-clickaway": "^2.2.2",
"vue-slider-component": "^3.2.15",
"vue-sweetalert2": "^5.0.2",
"vuedraggable": "^2.24.3"
},
"devDependencies": {
"autoprefixer": "^10.4.4",
"axios": "^0.26.1",
"bootstrap": "^4.6.0",
"bs-custom-file-input": "^1.3.4",
"cross-env": "^7.0.3",
"jquery": "^3.6.0",
"laravel-mix": "^6.0.43",
"laravel-mix-criticalcss": "^0.1.0",
"laravel-mix-purgecss": "^6.0.0",
"laravel-mix-workbox": "^0.1.4",
"livewire-sortable": "^0.2.2",
"lodash": "^4.17.21",
"popper.js": "^1.16.1",
"postcss": "^8.4.12",
"resolve-url-loader": "^5.0.0",
"sass": "^1.49.9",
"sass-loader": "^12.6.0",
"tailwindcss": "^3.0.23",
"vue": "^3.2.31",
"vue-template-compiler": "^2.6.14",
"workbox-webpack-plugin": "^6.5.1"
}
}

Try using a new version of Laravel Mix Critical.
npm i laravel-mix-criticalcss#latest --save-dev
Or use this package.json and do npm install.
{
"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"
},
"dependencies": {
"intersection-observer": "^0.12.0",
"laravel-vue-pagination": "^3.0.0",
"sass-migrator": "^1.5.4",
"v-lazy-image": "^2.1.1",
"vanilla-lazyload": "^17.6.1",
"vue-slider-component": "^3.2.15",
"vue-sweetalert2": "^5.0.2",
"vuedraggable": "^2.24.3"
},
"devDependencies": {
"autoprefixer": "^10.4.4",
"axios": "^0.26.1",
"bootstrap": "^4.6.0",
"bs-custom-file-input": "^1.3.4",
"cross-env": "^7.0.3",
"jquery": "^3.6.0",
"laravel-mix": "^6.0.43",
"laravel-mix-criticalcss": "^1.0.2",
"laravel-mix-purgecss": "^6.0.0",
"laravel-mix-workbox": "^0.1.4",
"livewire-sortable": "^0.2.2",
"lodash": "^4.17.21",
"popper.js": "^1.16.1",
"postcss": "^8.4.12",
"resolve-url-loader": "^5.0.0",
"sass": "^1.49.9",
"sass-loader": "^12.6.0",
"tailwindcss": "^3.0.23",
"vue": "^3.2.31",
"vue-template-compiler": "^2.6.14",
"workbox-webpack-plugin": "^6.5.1"
}
}

Related

How to apply Laravel + inertia + vue3 app changes to live server

I am working on a client's project, I have done changes in Vue and scss files, I want to know to can I deploy these changes to the live server.
The live website is on the digital ocean server. and its SSR(server-side rendering is on)
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix && mix --mix-config=webpack.ssr.mix.js",
"watch": "mix watch",
"watch-server": "mix watch --mix-config=webpack.ssr.mix.js",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "mix --production && mix --production --mix-config=webpack.ssr.mix.js",
"production": "mix --production",
"server": "nodemon public/js/ssr.js"
},
"devDependencies": {
"#popperjs/core": "^2.10.2",
"#vue/babel-plugin-jsx": "^1.1.1",
"axios": "^0.21",
"bootstrap": "^5.1.3",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"nodemon": "^2.0.15",
"postcss": "^8.1.14",
"resolve-url-loader": "^5.0.0",
"sass": "^1.32.11",
"sass-loader": "^11.0.1",
"vue-loader": "^17.0.0"
},
"dependencies": {
"#babel/plugin-syntax-dynamic-import": "^7.8.3",
"#duannx/vue-client-only": "^1.0.3",
"#inertiajs/inertia": "^0.11.0",
"#inertiajs/inertia-vue3": "^0.6.0",
"#inertiajs/progress": "^0.2.7",
"#inertiajs/server": "^0.1.0",
"#stripe/stripe-js": "^1.23.0",
"#vue/compiler-sfc": "^3.2.31",
"#vue/server-renderer": "^3.2.31",
"#vuepic/vue-datepicker": "^3.1.0",
"algoliasearch": "^4.13.1",
"inertia-title": "^1.0.2",
"jquery": "^3.6.0",
"moment": "^2.29.1",
"nprogress": "^0.2.0",
"slick-carousel": "^1.8.1",
"sprintf-js": "^1.1.2",
"vue": "^3.2.31",
"vue-instantsearch": "^4.3.3",
"vue-slick-carousel": "^1.0.6",
"vue-stripe-js": "^1.0.0",
"vue-timer-hook": "^1.0.0",
"vue-toastification": "^2.0.0-rc.5",
"vue3-autocounter": "^1.0.6",
"vue3-datepicker": "^0.3.2",
"vue3-lazyload": "^0.2.5-beta",
"vue3-select2-component": "^0.1.7",
"vuedraggable": "^4.1.0",
"webpack-node-externals": "^3.0.0"
}
}

Laravel Vuejs Uncaught ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization

I'm not able to see what's the problem here.
Compiling with npm run watch I get the below error.
I try differents things nothing, no clue where the error coming from
Error in the Console
> survey-front.js:126297 Uncaught ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization
at Module.default (survey-front.js:126297:42)
at Module../resources/js/router.js (RecordRTC.js:700:1)
at __webpack_require__ (survey-front.js:141859:42)
file survey-front.js
import Vue from 'vue'
Vue.component('survey-show', require('./components/SurveyShow.vue').default)
Vue.component('survey-language', require('./components/SurveySetLanguage.vue').default)
new Vue({
el: "#surveyElement"
})
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": {
"axios": "^0.21.1",
"bootstrap": "^4.6.0",
"browser-sync": "^2.27.9",
"cross-env": "^7.0.3",
"jquery": "^3.2",
"laravel-mix": "^6.0.43",
"lodash": "^4.17.21",
"popper.js": "^1.12",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.8",
"sass-loader": "^8.0.0",
"survey-knockout": "^1.9.26",
"vue": "^2.6.14",
"vue-loader": "^15.9.8",
"vue-template-compiler": "^2.6.14",
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2"
},
"dependencies": {
"inputmask": "^5.0.5",
"survey-vue": "^1.9.26",
"surveyjs-widgets": "^1.9.26",
"vue-router": "^3.5.1",
"vuetify": "^1.0.18"
}
}

Problem with Vue: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js)

I recently updated my repositories, and now I'm having these issues every time I build.
I already tried to go back to the previous point, but still the same. I found a problem with the style sheet. I use Tailwind, and when I import a sheet inside app.css if this sheet has these classes:
transform -translate-x-1/2 translate-y-1/2 can't compile
I took those classes out and put them in app.css, but when I use npm run watch, it compiles the first time, but if I do another modification, I have to save app.css again to compile correctly.
ERROR in ./resources/css/app.css
(./node_modules/css-loader/dist/cjs.js??clonedRuleSet-6.use[1]!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-6.use[2]!./resources/css/app.css)
Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
Problem with Vue building Module build failed (from
./node_modules/mini-css-extract-plugin/dist/loader.js)
package.json
{
"private": true,
"scripts": {
"lint": "eslint --ext .js,.vue resources/js/",
"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": {
"#types/sanitize-html": "^2.3.2",
"#vue/compiler-sfc": "^3.1.4",
"autoprefixer": "^10.4.0",
"axios": "^0.21",
"cssnano": "^5.0.7",
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier-vue": "^3.1.0",
"eslint-plugin-vue": "^7.14.0",
"laravel-mix": "^6.0.42",
"lodash": "^4.17.19",
"mini-css-extract-plugin": "^1.6.2",
"postcss": "^8.4.5",
"postcss-import": "^14.0.2",
"postcss-loader": "^6.2.1",
"prettier": "^2.3.2",
"tailwindcss": "^3.0.23",
"vue-loader": "^16.3.0"
},
"dependencies": {
"#chenfengyuan/vue-barcode": "^2.0.0-beta",
"#fortawesome/fontawesome-svg-core": "^1.2.35",
"#fortawesome/free-brands-svg-icons": "^5.15.4",
"#fortawesome/free-solid-svg-icons": "^5.15.3",
"#fortawesome/vue-fontawesome": "^3.0.0-4",
"ag-grid-community": "^25.3.0",
"ag-grid-vue3": "^25.3.1",
"click-outside-vue3": "^4.0.1",
"dayjs": "^1.10.7",
"jsbarcode": "^3.11.4",
"laravel-echo": "^1.11.3",
"mini-css-extract-plugin": "^2.5.3",
"pusher-js": "^7.0.6",
"peru-ubigeo": "^0.0.3",
"qrcode.vue": "^3.2.2",
"quagga": "^0.12.1",
"twitter-widgets": "^2.0.0",
"vue": "^3.1.5",
"vue-3-sanitize": "^0.1.3",
"vue-class-component": "^8.0.0-rc.1",
"vue-cookie-next": "^1.0.3",
"vue-currency-input": "^2.0.0",
"vue-debounce": "^3.0.1",
"vue-router": "^4.0.12",
"vue-upload-drop-images": "^1.0.7",
"vue2-datepicker": "^4.0.0-beta.2",
"vuex": "^4.0.2"
}
I use Vue 3 and Laravel 8

This relative module was not found: * ./src/main.js in multi ./src/main.js

npm run build error!
I try all solutions for this problem but still not able to solve this. Many times i reinstall npm but not get proper solution (Laravel 8 and Vue js) enter image description here
My package.json Code
{
"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",
"serve": "vue-cli-service serve",
"build": "vue-cli-service build"
},
"devDependencies": {
"#webpack-cli/init": "^1.1.3",
"axios": "^0.21.1",
"babel-loader": "^8.2.2",
"bootstrap": "^4.6.0",
"jquery": "^3.6",
"laravel-mix": "^6.0.13",
"lodash": "^4.17.21",
"popper.js": "^1.12",
"postcss": "^8.2.8",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.8",
"sass-loader": "^11.0.1",
"vue": "^2.6.12",
"vue-loader": "^15.9.6",
"vue-template-compiler": "^2.6.12",
"webpack": "^5.28.0",
"webpack-cli": "^4.6.0"
},
"dependencies": {
"vue": "^2.6.12",
"vue-router": "^3.5.1"
}
}
I created a src folder(inside root) with a blank main.js file and it worked for me: reference is here

Npm run watch not working changes in Laravel

I have this issue in laravel I already run npm run watch and when I tried changing some value then save and when I refresh, it does not change. It would be great if anybody could figure out, thank you so much in advance!.
The thing is when I terminate and rerun the npm run watch it changes the update but it so hassle to terminate all over again in order to see the updates to your program
what I tried
npm watch-poll
I already tried clearing the cache on my chrome browser
I'm been using laragon is there any issue in my laragon? Or I guess the issue is on my chrome browser?
This is my 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": {
"axios": "^0.21",
"bootstrap": "^4.0.0",
"jquery": "^3.2",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"popper.js": "^1.12",
"postcss": "^8.1.14",
"resolve-url-loader": "^3.1.2",
"sass": "^1.20.1",
"sass-loader": "^8.0.0",
"vue": "^2.5.17",
"vue-loader": "^15.9.5",
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
"vue-router": "^3.5.1"
}
}
This is the file that I changed my index.vue When I change the value from Hello_value into some value it didn't change
<template>
<div>
<router-link v-bind:to="{name: 'home'}">Hello_value</router-link>
<router-link v-bind:to="{name: 'second'}">Second</router-link>
<router-view></router-view>
</div>
</template>
I've been curious what's wrong using npm run watch and I just starting learning laravue
Try updating package.json to the following and then run npm install.
{
"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",
"bootstrap": "^5.0.2",
"css-loader": "^5.2.7",
"jquery": "^3.6",
"laravel-mix": "^6.0.25",
"lodash": "^4.17.21",
"popper.js": "^1.12",
"postcss": "^8.3.5",
"resolve-url-loader": "^4.0.0",
"sass": "^1.35.2",
"sass-loader": "^12.1.0",
"vue": "^2.6.14",
"vue-loader": "^15.9.6",
"vue-router": "^3.5.2",
"vue-template-compiler": "^2.6.14"
}
}

Resources