I'm using laravel nova 4 for creating an admin panel. I'm trying to override a existed nova component. This is what I have done:
Create BelongsToField.vue in resources/js/nova/components/Form, then copy all context in vendor/laravel/nova/resources/js/components/Form/BelongsTo.vue
Add fields.js file in resources/js/nova, this is my file:
import BelongsToField from './components/Form/BelongsToField'
Nova.booting((app, store) => {
app.component('FormBelongsToField', BelongsToField);
})
Then create webpack.mix.js:
const mix = require('laravel-mix');
const path = require('path');
mix.setPublicPath('public')
.js('resources/js/nova/fields.js', 'js')
.vue({ version: 3 });
Then, adding script to NovaServiceProvider
public function boot()
{
parent::boot();
Nova::serving(function (ServingNova $event) {
Nova::script('belongs-to-field', __DIR__ . '/../../public/js/fields.js');
});
}
Because laravel nova 4 uses vite instead of webpack, so I migrate back my application to use s webpack following this (I tried with vite, but it doesn't work, so I change to webpack)
After install all dependencies, this 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",
"prepare": "husky install"
},
"devDependencies": {
"#commitlint/cli": "^17.0.3",
"#commitlint/config-conventional": "^17.0.3",
"#vitejs/plugin-vue": "^2.3.3",
"#vue/babel-plugin-jsx": "^1.1.1",
"#vue/compiler-sfc": "^3.2.22",
"axios": "^0.25",
"form-backend-validation": "^2.3.3",
"husky": "^8.0.1",
"laravel-mix": "^6.0.41",
"lodash": "^4.17.21",
"postcss": "^8.3.11",
"vue-loader": "^16.8.3"
},
"dependencies": {
"#inertiajs/inertia": "^0.11.0",
"inflector-js": "^1.0.1",
"vue": "^3.2.37",
"vuex": "^4.0.2"
}
}
Then I run npm run dev to build .js file to public folder, build process succeeded, but component doesn't show up, and Vue displays a warning
I tried to override by using laravel nova custom field and change component field in .php file to belongs-to-field. Vue file context is copied same with origin file in vendor (BelongsToField.vue). After building component, it worked!
Thus, I think my problem not come from component file, it could be from Vue version or webpack config but I'm just new to Vue and cannot debug this error. Can someone help.
For more information: I've used this approach in laravel nova 3, and it worked.
Related
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.
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
I am facing this critical error while installing Laravel Inertia with Jetstream.
larevel new projectName --jet
Then I get this:
WARNING in ./resources/js/app.js 16:65-76 Critical dependency:
Accessing import.meta directly is unsupported (only property access is
supported)
webpack compiled with 1 warning
When I run the project, i can see only #vite('resources/js/app.js') in the browser[1]: https://i.stack.imgur.com/WjQct.png
resources/js/app.js
import "./bootstrap";
import "../css/app.css";
import { createApp, h } from "vue";
import { createInertiaApp } from "#inertiajs/inertia-vue3";
import { InertiaProgress } from "#inertiajs/progress";
import { resolvePageComponent } from "laravel-vite-plugin/inertia-helpers";
import { ZiggyVue } from "../../vendor/tightenco/ziggy/dist/vue.m";
const appName =
window.document.getElementsByTagName("title")[0]?.innerText || "Laravel";
createInertiaApp({
title: (title) => `${title} - ${appName}`,
resolve: (name) =>
resolvePageComponent(
`./Pages/${name}.vue`,
import.meta.glob("./Pages/**/*.vue")
),
setup({ el, app, props, plugin }) {
return createApp({ render: () => h(app, props) })
.use(plugin)
.use(ZiggyVue, Ziggy)
.mount(el);
},
});
InertiaProgress.init({ color: "#4B5563" });
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": {
"#inertiajs/inertia": "^0.11.0",
"#inertiajs/inertia-vue3": "^0.6.0",
"#inertiajs/progress": "^0.2.7",
"#tailwindcss/forms": "^0.5.2",
"#tailwindcss/typography": "^0.5.2",
"#vitejs/plugin-vue": "^2.3.3",
"autoprefixer": "^10.4.7",
"axios": "^0.21",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"postcss": "^8.4.14",
"tailwindcss": "^3.1.0",
"vue": "^3.2.31"
}
}
webpack.config.js
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', [
//
]);
I can't see the default Laravel layout view or the login/register views.
Sir, if you have PHP version < 8 and Laravel version < 9 then update the PHP version to 8 and Laravel version to 9. It will fix your problem.
To check Laravel verion run:
php artisan --version
To check PHP version run: php --version
Please check Support Policy of laravel on official site.
Try to install laravel-vite-plugin:
First of install the laravel-vite plugin just using this command.
npm install --save-dev vite laravel-vite-plugin
npm install --save-dev #vitejs/plugin-vue
Then you need to execute the following command.
npm install
npm run dev
php artisan migrate
and Now, your error must be solved
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']
}
]
}
}
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