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

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

Related

Uncaught Error: (mdc-auto-init) Could not find constructor in registry for MDCTabBar

I'm trying to use Laravel Mix to include Material Components Web in my Laravel 8 project. I've installed the NPM packages and I am able to successfully compile using mix. However when I run the application I get an error console saying the components don't exist in the registry. It looks to me like I'm not including the autoinit registry startup that material-web-components has but I'm not sure why the components aren't registering. The goal is for the components to successfully auto init.
The pages that contain the components are using blade views and are not using typescript.
I am able to successfully auto initialize if I use the CDN version of material web components, but then I don't gain any benefits from typescript since the types won't be found.
Error in console
Example component being used in blade
<label class="mdc-text-field mdc-text-field--outlined mdc-wide-label" data-mdc-auto-init="MDCTextField" >
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": {
"#types/node": "^18.6.3",
"axios": "^0.21",
"laravel-mix": "^6.0.49",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"resolve-url-loader": "^5.0.0",
"sass": "^1.54.0",
"sass-loader": "^12.1.0",
"ts-loader": "^9.3.1",
"typescript": "^4.7.4"
},
"dependencies": {
"#material/auto-init": "^14.0.0",
"#types/jquery": "^3.5.14",
"#types/toastr": "^2.1.39",
"jquery": "^3.6.0",
"material-components-web": "^14.0.0",
"toastr": "^2.1.4"
}
}
webpack.mix.js
const mix = require('laravel-mix');
mix.ts('resources/assets/js/*', 'public/js/app.js').version()
.sourceMaps();
mix.sass('resources/sass/app.scss', 'public/css/app.css', {
sassOptions: {
implementation: require('sass'),
webpackImporter: false,
sassOptions: {
includePaths: ['./node_modules']
},
}
});
app.ts
import * as mdc from 'material-components-web';
mdc.autoInit();
Try
import mdcAutoInit from '#material/auto-init';
mdcAutoInit();
P.S. I'm not a Laravel developer, so I can't check it myself.
P.P.S. These docs might be of help - https://github.com/material-components/material-components-web/tree/master/packages/mdc-auto-init

Blank page is showing laravel and vue

Info
Using laravel and vue project
After installing composer install and npm install blank page is showing
Laravel 8, Vue vue#3.2.31, PHP 8 and ubuntu 20
Project location /www/html/project
Start the project using php artisan serve
Network tab http://127.0.0.1:8000/ showing status 200 but in preview tab
Error
No warning and console error. Network tab http://127.0.0.1:8000/ showing status 200 but in the preview tab below error gives
There was a problem loading your site type details
Code
Webpack.mix.js
const plugins = [
require('postcss-import'),
require('tailwindcss'),
require('postcss-nested'),
require('autoprefixer')
];
mix
.webpackConfig({
resolve: {
alias: {
'#': __dirname + '/resources/js'
}
}
})
.js('resources/js/project/app.js', 'public/js').vue().version()
.js('resources/js/_default/admin.js', 'public/js').vue().version()
.postCss('resources/css/app.css', 'public/css', plugins)
.postCss('resources/css/admin.css', 'public/css', plugins)
.sass('resources/css/admin/bootstrap.custom.scss', 'public/css')
//.browserSync('127.0.0.1:8000')
//mix.dumpWebpackConfig();
if (mix.inProduction()) {
mix.version();
}
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": {
"#vue/compiler-sfc": "^3.2.20",
"autoprefixer": "^10.4.0",
"axios": "^0.21",
"browser-sync": "^2.27.7",
"browser-sync-webpack-plugin": "^2.3.0",
"laravel-mix": "^6.0.0-beta.17",
"lodash": "^4.17.19",
"popper.js": "^1.16.1",
"postcss": "^8.3.11",
"postcss-import": "^12.0",
"postcss-nested": "^4.2",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.11",
"sass-loader": "^11.1.1",
"tailwindcss": "^2.2.19",
"vue": "^3.2.20",
"vue-loader": "^16.8.2",
"vue-template-compiler": "^2.6.12"
},
"dependencies": {
"#headlessui/vue": "^1.4.1",
"#heroicons/vue": "^1.0.5",
"#tailwindcss/forms": "^0.3.4",
"bootstrap": "^4.6.1",
"formiojs": "^4.13.11",
"install": "^0.13.0",
"npm": "^8.1.1",
"or": "^0.2.0",
"vue-i18n": "^8.26.5",
"vue-router": "^4.0.12",
"webpack-shell-plugin-next": "^2.2.2"
}
}
I don't know what's wrong with this project, I tried deleting the node_modules and npm install but still got the same error, npm run hot also did not gives any error
const path = require('path');
mix.js(['resources/js/app.js','resources/js/_default/admin.js'], "public/js")
.vue()
.postCss(['resources/css/app.css', 'resources/css/admin.css'], "public/css", plugins)
.sass('resources/css/admin/bootstrap.custom.scss', 'public/css')
.webpackConfig({
resolve: {
alias: {
'#': path.resolve('resources/js'),
},
},
};);
if (mix.inProduction()) {
mix.version();
}

Laravel Mix / Tailwind compiling issue with css-loader

I am trying to compile my CSS using PostCSS in Laravel Mix - Laravel 8.50.0 (as stated in Install Tailwind CSS with Laravel), but when I compile my assets using: npm run watch I receive the following error.
ERROR in ./resources/css/app.css
(./node_modules/css-loader/dist/cjs.js??clonedRuleSet-6[0].rules[0].use1!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-6[0].rules[0].use[2]!./resources/css/app.css)
Module build failed (from ./node_modules/css-loader/dist/cjs.js):
ValidationError: Invalid options object. CSS Loader has been
initialized using an options object that does not match the API
schema.
options.url should be one of these:
boolean | object { filter? }
-> Allows to enables/disables url()/image-set() functions handling.
-> Read more at https://github.com/webpack-contrib/css-loader#url
Details:
options.url should be a boolean.
options.url should be an object:
object { filter? }
at validate (/Users/usser/Desktop/GIT/snitch/onesnitch.com/node_modules/webpack/node_modules/schema-utils/dist/validate.js:105:11)
at Object.getOptions (/Users/usser/Desktop/GIT/snitch/onesnitch.com/node_modules/webpack/lib/NormalModule.js:527:19)
at Object.loader (/Users/usser/Desktop/GIT/snitch/onesnitch.com/node_modules/css-loader/dist/index.js:31:27)
Child mini-css-extract-plugin
/Users/usser/Desktop/GIT/snitch/onesnitch.com/node_modules/css-loader/dist/cjs.js??clonedRuleSet-6[0].rules[0].use1!/Users/usser/Desktop/GIT/snitch/onesnitch.com/node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-6[0].rules[0].use[2]!/Users/usser/Desktop/GIT/snitch/onesnitch.com/resources/css/app.css
compiled with 1 error
webpack.mix.js
const mix = require("laravel-mix");
mix.webpackConfig({
stats: {
children: true,
},
})
.options({
terser: {
extractComments: false,
},
})
.js("resources/js/app.js", "public/js")
.vue({ version: 2 })
.postCss("resources/css/app.css", "public/css", [require("tailwindcss")])
.js("resources/frontend/js/app.js", "public/js/frontend")
.postCss("resources/frontend/css/app.css", "public/css/frontend", [
require("tailwindcss"),
])
.version();
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": {
"autoprefixer": "^10.2.5",
"axios": "^0.21.1",
"css-loader": "^6.1.0",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"postcss": "^8.3.5",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.8",
"sass-loader": "^10.1.1",
"tailwindcss": "^2.1.1",
"vue-loader": "^15.9.6",
"vue-template-compiler": "^2.6.12"
},
"dependencies": {
"#tailwindcss/aspect-ratio": "^0.2.0",
"#tailwindcss/forms": "^0.3.2",
"#tailwindcss/typography": "^0.4.0",
"alpinejs": "^2.8.2",
"aos": "^3.0.0-beta.6",
"dayjs": "^1.10.4",
"dotenv": "^8.2.0",
"secure-ls": "^1.2.6",
"vee-validate": "^3.4.5",
"vue": "^2.6.12",
"vue-i18n": "^8.24.1",
"vue-router": "^3.5.1",
"vuex": "^3.6.2",
"vuex-persistedstate": "^3.2.0",
"zxcvbn": "^4.4.2"
}
}
Thoughts would be greatly appreciated.
As a workaround, downgrade your css-loader package to a 5.x version.
npm install css-loader#5.2.7 --save-dev

NPM build failing with Webpack 5

About a day or 2 ago, I ran my NPM build, but it suddenly gave the error that the polyfill is not provided by default anymore with Webpack 5. I was able to fix a lot of the errors, but it keeps failing.
I get the following errors:
These are just a few of them.
I'm using laravel-mix#6.0.13 in this build with the following webpack.mix.js file:
const mix = require('laravel-mix');
require('mix-tailwindcss');
mix.webpackConfig({
resolve: {
fallback: {
fs: require.resolve('browserify-fs'),
path: require.resolve("path-browserify"),
"crypto": require.resolve("crypto-browserify"),
"https": require.resolve("https-browserify"),
"http": require.resolve("stream-http"),
"vm": require.resolve("vm-browserify"),
"os": require.resolve("os-browserify/browser"),
"stream": require.resolve("stream-browserify"),
"constants": require.resolve("constants-browserify"),
}
}
})
mix.options({ legacyNodePolyfills: false });
mix.js('resources/js/app.js', 'public/js').vue()
.sass('resources/scss/app.scss', 'public/css')
.tailwind('./tailwind.config.js')
mix.sass('resources/scss/admin.scss', 'public/css')
My packages.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.18",
"bootstrap": "^4.0.0",
"browserify-fs": "^1.0.0",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^6.0.13",
"lodash": "^4.17.4",
"mix-tailwindcss": "^1.3.0",
"popper.js": "^1.12",
"postcss": "^8.1",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.12",
"sass-loader": "10.*",
"tailwindcss": "^2.1.2",
"vue": "^2.5.7",
"vue-loader": "^15.9.5",
"vue-template-compiler": "^2.6.12"
},
"dependencies": {
"buefy": "^0.9.6",
"jquery": "^3.6.0",
"mix-tailwindcss": "^1.3.0",
"query-string": "^7.0.0",
"slick-carousel": "^1.8.1",
"vue": "^2.6.12",
"vue-it-bigger": "^0.2.2"
}
}
Does someone know how to fix this?
Solved it!
I added the the NodePolyfillPlugin plugin to my webpack config. I added browserify-fs to resolve.fallback.fs like this.
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
mix.webpackConfig({
plugins: [
new NodePolyfillPlugin(),
],
resolve: {
fallback: {
fs: require.resolve('browserify-fs'),
}
}
})
After this the build kept failing, i finally figured out that for some reason i had import {vue} from 'laravel-mix' in my app.js . this was giving als the errors. After removing this it ran succesfully!

FullCalendar is not defined. Laravel 8 Fullcalendar-scheduler version 5.6 es6

Uncaught ReferenceError: FullCalendar is not defined when
npm install. If I use the cdn source inside my calendar blade. Calendar will display correctly. However, I change to npm install and I am stuck
composer install
npm i
npm run dev
webpack.mix.js
let mix = require("laravel-mix");
let productionSourceMaps = false;
mix.js('resources/js/app.js', 'public/js')
mix.sass('resources/sass/app.scss', 'public/css')
.sourceMaps()
if (mix.inProduction()) {
mix.version();
}
app.js
import 'jquery';
require('./bootstrap');
import 'moment';
import 'fullcalendar-scheduler';
app.scss
#import "~bootstrap/dist/css/bootstrap.css";
#import "~fullcalendar-scheduler/main.css";
#import "~bootstrap-select/dist/css/bootstrap-select.min.css";
#import "~shop-item/dist/bootstrap/css/bootstrap.css";
#import "~font-awesome/css/font-awesome.css";
#import "variables";
package.json
{
"private": true,
"scripts": {
"dev": "mix",
"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",
"css-loader": "^5.2.1",
"laravel-mix": "^6.0.16",
"lodash": "^4.17.21",
"postcss": "^8.2.10",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.10",
"sass-loader": "^11.0.1"
},
"dependencies": {
"autoprefixer": "^10.2.5",
"bootstrap": "^4.5.3",
"bootstrap-datetimepicker": "0.0.7",
"bootstrap-select": "^1.13.18",
"chartjs": "^0.3.24",
"datatables.net": "^1.10.24",
"font-awesome": "^4.7.0",
"fullcalendar-scheduler": "5.6.0",
"jquery": "^3.6.0",
"moment": "^2.29.1",
"popper.js": "^1.16.1",
"style-loader": "^2.0.0",
"waypoints": "^4.0.1",
"webpack": "^5.35.0",
"webpack-cli": "^4.6.0"
}
}
With Webpack, it's always better to use "require" instead of "import" in app.js
So try this:
var moment = require ('moment');
require ('fullcalendar-scheduler');
I finally got... I just had not learned enough yet.. But, hope this helps others.
I needed both a webpack.config.js and a webpack.mix.js and a little work on the package.json. Here are the changes that worked for me. Also, I could never get npm i fullcalendar-scheduler to work in the build.. I had to use #fullcalendar
webpack.config.js
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports = {
mode: 'development',
devtool: 'source-map',
entry: './resources/fullcalendar/main.js',
resolve: {
extensions: [ '.js' ]
},
module: {
rules: [
{
test: /\.css$/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{ loader: 'css-loader', options: { importLoaders: 1 } }
]
}
]
},
output: {
filename: 'main.js',
path: path.join(__dirname, 'public/dist')
},
plugins: [
new MiniCssExtractPlugin({
filename: 'main.css'
})
]
}
webpack.mix.js
let mix = require("laravel-mix");
mix
.js("resources/js/app.js", "public/js")
.sass("resources/sass/app.scss", "public/css");
package.json
{
"private": true,
"scripts": {
"dev": "mix && npm run build",
"development": "mix",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production",
"build": "webpack",
"watch": "webpack --watch",
"clean": "rm -rf dist"
},
"devDependencies": {
"css-loader": "^4.3.0",
"laravel-mix": "^6.0.18",
"mini-css-extract-plugin": "^1.2.0",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.11",
"sass-loader": "^11.0.1",
"webpack": "^5.3.0",
"webpack-cli": "^4.1.0"
},
"dependencies": {
"#fullcalendar/adaptive": "^5.6.0",
"#fullcalendar/core": "^5.6.0",
"#fullcalendar/daygrid": "^5.6.0",
"#fullcalendar/interaction": "^5.6.0",
"#fullcalendar/list": "^5.6.0",
"#fullcalendar/resource-timeline": "^5.6.0",
"#fullcalendar/timegrid": "^5.6.0",
"autoprefixer": "^10.2.5",
"bootstrap": "^4.6.0",
"jquery": "^3.6.0",
"webpack": "^5.35.0",
"webpack-cli": "^4.6.0"
}

Resources