Component is missing template or render function - VueJS Library - vue.js

I am trying to create an SVG library using Vue3 but all I am getting is error...I created the basic library project following this article. Here is my file structure
and this is my code in BaseIcon.vue
<template>
<component :is="iconComponent" class="inline-block fill-current"
style="height: 1em; width: 1em; vertical-align: -0.125em" />
</template>
<script>
const icons = {}
const requireComponents = require.context('../assets/icons/', false, /.svg$/)
requireComponents.keys().forEach(fileName => {
const iconName = fileName.replace(/^\.\/icon-(.+)\.svg$/, '$1')
const componentConfig = requireComponents(fileName)
icons[iconName] = componentConfig.default || componentConfig
})
export default {
props: {
name: {
type: String,
required: true,
validator(value) {
return Object.prototype.hasOwnProperty.call(icons, value)
}
}
},
computed: {
iconComponent() {
return icons[this.name]
},
}
}
</script>
This is the App.vue file code
<template>
<div id="app" class="p-10 text-xl">
<BaseIcon name="user" class="text-blue-500" /> Home
<BaseIcon name="home" class="text-blue-500" /> Profile
</div>
</template>
<script>
import BaseIcon from './BaseIcon.vue'
export default {
name: 'App',
components: {
BaseIcon,
}
}
</script>
My Index.js looks like this
/* eslint-disable import/prefer-default-export */
export { default as App } from './App.vue'
Dev Dependencies in my Package.json are these:
"devDependencies": {
"#babel/core": "^7.14.6",
"#babel/preset-env": "^7.14.7",
"#rollup/plugin-alias": "^3.1.2",
"#rollup/plugin-babel": "^5.3.0",
"#rollup/plugin-commonjs": "^14.0.0",
"#rollup/plugin-node-resolve": "^9.0.0",
"#rollup/plugin-replace": "^2.4.2",
"#vue/cli-plugin-babel": "^4.5.13",
"#vue/cli-service": "^4.5.13",
"#vue/compiler-sfc": "^3.1.0-0",
"cross-env": "^7.0.3",
"minimist": "^1.2.5",
"postcss": "^8.2.10",
"rimraf": "^3.0.2",
"rollup": "^2.52.8",
"rollup-plugin-postcss": "^4.0.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-vue": "^6.0.0",
"vue-loader": "16.8.3",
"vue-svg-loader": "^0.17.0-beta.2",
"vue": "^3.0.5"
},
and I've added vue.config.json with following settings:
module.exports = {
chainWebpack: (config) => {
const svgRule = config.module.rule('svg');
svgRule.uses.clear();
svgRule
.use('babel-loader')
.loader('babel-loader')
.end()
.use('vue-svg-loader')
.loader('vue-svg-loader');
},
};
And here is what I am getting as error:
I'm not sure what I am missing here, or what is wrong.. Any kind of help will be appreciated, because its been days that I am stuck here and just couldn't get any idea of resolving this.

Related

Nuxt 2 & Vuelidate 2 not working properly

I have installed vuelidate 2 to validate forms in my NuxtJS project. I followed instructions for installation and setup according to vuelidate documentation. This is how my setup files look until now:
Package.json
"dependencies": {
"#nuxtjs/axios": "^5.13.6",
"#vue/composition-api": "^1.6.1",
"#vuelidate/core": "^2.0.0-alpha.41",
"#vuelidate/validators": "^2.0.0-alpha.29",
"core-js": "^3.19.3",
"nuxt": "^2.15.8",
"vue": "^2.6.14",
"vue-server-renderer": "^2.6.14",
"vue-template-compiler": "^2.6.14",
"vuelidate": "^0.7.7",
"webpack": "^4.46.0"
},
plugins/composition-api.js for #vue/composition-api
import Vue from 'vue'
import VueCompositionAPI from '#vue/composition-api'
Vue.use(VueCompositionAPI)
plugins/vuelidate.js
import Vue from 'vue'
import Vuelidate from 'vuelidate'
Vue.use(Vuelidate)
nuxt.config.js
plugins: [
{ src: '~/plugins/composition-api.js' },
{ src: '~/plugins/vuelidate' },
],
components/form.vue
<template>
<form #submit.prevent="submitForm">
<div>
<label for="name">Name:</label>
<input v-model="name" type="text" name="name" />
</div>
<button>Submit</button>
</form>
</template />
<script>
import useVuelidate from '#vuelidate/core'
import { required } from '#vuelidate/validators'
export default {
setup() {
return { v$: useVuelidate() }
},
data() {
return {
name: '',
}
},
methods: {
submitForm() {
this.v$.$validate().then((isFormValid) => {
if (isFormValid) {
console.log('valid!!!', this.$v)
} else {
return console.log('false', this.$v)
}
})
},
},
validations() {
return {
name: {
required,
},
}
},
}
</script>
These are a couple of problems that occur:
When I place v-if="v$.name.$error" inside template I get the error Cannot read property 'name' of undefined.
When I call submitForm method, the validation of isFormValid works properly. When I open the console to observe $v.errors, $v.dirty, or $v.invalid, I see this error inside the array:
[Exception: RangeError: Maximum call stack size exceeded at Watcher.depend (webpack-internal...

Jest Unit test cant determine Vuetify components visibility

I have a Vue2 project with Vuetify, and i am using Jest for unit testing my code. I am starting out testing some sample code and i simple cannot get Jest to determine if a Vuetify v-alert component is visible or not. I have tried the built in Jest methods as well as adding Jest-dom and using the toBeVisible() method and nothing is working so far.
If you look at the Test.vue component, the v-alert component is hidden by default.(Its style is set to display: none;)
The unit test says expect(alert).not.toBeVisible() which should pass, but it always fails regardless of what the v-alert model is set to. If i change the test to expect(alert).toBeVisible() it passes regardless of the v-alert model is set to true/false.
If i change the test to be expect(alert).toHaveStyle({ display: 'none' }); it fails regardless of if i have the model set to true/false.
So as far as i can tell the Jest unit test CANNOT determine the visibility of the v-alert component at all. These same test work fine on the v-btn component just fine so why does the v-alert break? This is just my first unit test sample that ive been trying to get working for 2 days now. I have an entire application to write tests for and so far Jest is not working very well with Vuetify...any suggestions?
// Test.vue component
<template>
<div>
<v-btn ref="btn" depressed tile #click="showAlert">Show Alert</v-btn>
<v-alert
v-model="showError"
ref="error-msg"
type="error"
transition="scale-transition"
width="410"
tile
dense
dismissible
#input="clearError"
>
{{ errorText }}
</v-alert>
</div>
</template>
<script>
export default {
data() {
return {
showError: false,
errorText: ''
};
},
methods: {
showAlert() {
this.errorText = 'Test Error message';
this.showError = true;
},
clearError() {
this.errorText = '';
}
}
};
</script>
// Jest Unit test
// Libraries
import Vue from 'vue';
import Vuetify from 'vuetify';
// Components
import Test from '#/components/Login/Test.vue';
// Utilities
import { createLocalVue, shallowMount } from '#vue/test-utils';
// Import Jest Dom test utils.
import '#testing-library/jest-dom';
const localVue = createLocalVue();
Vue.use(Vuetify);
describe('Test Page', () => {
let vuetify;
beforeEach(() => {
vuetify = new Vuetify();
});
it('Check visibility of button', () => {
const wrapper = shallowMount(Test, {
localVue,
vuetify
});
const btn = wrapper.findComponent({ ref: 'btn' }).element;
expect(btn).toBeVisible();
});
it('Error Message hidden on page load', () => {
const wrapper = shallowMount(Test, {
localVue,
vuetify
});
const alert = wrapper.findComponent({ ref: 'error-msg' }).element;
expect(alert).not.toBeVisible();
});
});
// Package.json
"dependencies": {
"vue": "^2.6.11",
"vue-click-outside": "^1.1.0",
"vue-debounce": "^2.5.7",
"vue-router": "^3.3.4",
"vuetify": "^2.2.11",
"vuex": "^3.4.0"
},
"devDependencies": {
"#babel/plugin-transform-runtime": "^7.10.3",
"#babel/polyfill": "^7.10.1",
"#fortawesome/fontawesome-free": "^5.13.1",
"#testing-library/jest-dom": "^5.10.1",
"#vue/cli-plugin-babel": "^4.4.5",
"#vue/cli-plugin-e2e-nightwatch": "^4.4.5",
"#vue/cli-plugin-eslint": "^4.4.5",
"#vue/cli-plugin-unit-jest": "^4.4.5",
"#vue/cli-service": "^4.4.5",
"#vue/eslint-config-prettier": "^4.0.1",
"#vue/test-utils": "^1.0.3",
"babel-eslint": "^10.0.3",
"babel-jest": "^26.1.0",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^6.2.2",
"node-sass": "^4.14.1",
"sass": "^1.26.9",
"sass-loader": "^8.0.2",
"vue-cli-plugin-vuetify": "^2.0.6",
"vue-template-compiler": "^2.6.11",
"vuetify-loader": "^1.5.0"
}
I ran into a similar issue, so I decided to use exists from #vue/test-utils instead.
Docs for exists: https://vue-test-utils.vuejs.org/api/wrapper/#exists
I also decided to use v-if (instead of v-model) on the v-alert element to hide / show the component.
It looks like if v-if receives a value of false, the component/element in the document is replaced with <!---->, which is great for checking if your component/element is hidden or displayed.
See v-if test spec: https://github.com/vuejs/vue/blob/52719ccab8fccffbdf497b96d3731dc86f04c1ce/test/unit/features/directives/if.spec.js
SFC
Template:
<template>
<v-container>
<v-btn
#click='showError()'
ref="showErrorButton">
Show Error
</v-btn>
<v-alert
v-if="errorEncountered"
ref="errorAlert"
colored-border
type="error"
elevation="2"
>
Oops! Something went wrong!
</v-alert>
<v-container>
<template>
Javascript:
export default {
methods: {
showError() {
this.errorEncountered = true;
}
}
data() {
return {
errorEncountered: false,
};
},
};
Whenever errorEncountered is updated, the v-alert component will show/hide depending on whether the value is true/false.
Tests
describe('Component', () => {
let wrapper;
beforeEach(() => {
wrapper = mount(Component, {
localVue,
vuetify,
});
});
describe('When component is mounted', () => {
it('Then the default value for errorEncountered should be false', () => {
expect(wrapper.vm.errorEncountered).toBeFalse();
});
it('Then the default state for the error alert should be hidden', async () => {
const errorAlert = wrapper.find({ ref: 'errorAlert' });
expect(errorAlert.exists()).toBeFalse();
});
describe('When an error is encountered', () => {
it('Then errorEncountered should be set to true', async () => {
const showErrorButton = wrapper.find({ ref: 'showErrorButton' });
showErrorButton.trigger('click');
await Vue.nextTick();
expect(wrapper.vm.errorEncountered).toBeTrue();
});
it('Then error alert should be visible', async () => {
const showErrorButton = wrapper.find({ ref: 'showErrorButton' });
showErrorButton.trigger('click');
await Vue.nextTick();
const errorAlert = wrapper.find({ ref: 'errorAlert' });
expect(errorAlert.exists()).toBeTrue();
});
});
});

webpack 4 aspnetcore 2.2 HMR not reloading in browser

I'm unable to rule out a compatibility issue with aspnetcore 2.2 and webpack 4 or a configuration issue on my end.
I need some help spotting the configuration issue if that is the cause.
ASPNETCORE 2.2
WEBPACK 4
When I make a change to a ".tsx" file, Visual Studio outputs that webpack has rebuilt, however the browser is not refreshing and there are no messages in the console. (I do however get the initial HMR connected message in the browser console).
Visual Studio output:
Microsoft.AspNetCore.NodeServices:Information: webpack building...
Microsoft.AspNetCore.NodeServices:Information: Checking
started in a separate process...
754ms Microsoft.AspNetCore.NodeServices:Information: webpack built
1e45bf5f88ad514f4a12 in 4940ms
Compiled successfully.
starting HTTP/1.1 GET https://localhost:44331/__webpack_hmr
webpack.config.js:
const path = require('path');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpack = require('webpack');
module.exports = (env) => {
const isDevBuild = !(env && env.prod);
const outputDir = (env && env.publishDir)
? env.publishDir
: __dirname;
return [{
mode: isDevBuild ? 'development' : 'production',
devtool: 'inline-source-map',
stats: { modules: false },
entry: { 'main': './client/boot.tsx' },
watchOptions: {
ignored: /node_modules/
},
output: {
filename: "dist/[name].js",
path: path.join(outputDir, 'wwwroot'),
publicPath: '/'
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".json"]
},
devServer: {
hot: true
},
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.tsx?$/,
include: /client/,
loader: [
{
loader: 'awesome-typescript-loader',
options: {
useCache: true,
useBabel: true,
babelOptions: {
babelrc: false,
plugins: ['react-hot-loader/babel'],
}
}
}
]
},
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
]
},
plugins: [
new CleanWebpackPlugin(path.join(outputDir, 'wwwroot', 'dist')),
new CheckerPlugin()
]
}];
};
Startup.cs Configure:
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true
});
}
package.json:
"devDependencies": {
"#babel/core": "*",
"#babel/preset-env": "*",
"#types/history": "4.6.0",
"#types/jest": "^23.3.2",
"#types/node": "^10.9.1",
"#types/react": "^16.7.13",
"#types/react-dom": "16.0.11",
"#types/react-hot-loader": "3.0.3",
"#types/react-router": "4.4.1",
"#types/react-router-dom": "4.3.1",
"#types/webpack-env": "^1.13.6",
"aspnet-webpack": "^3.0.0",
"awesome-typescript-loader": "^5.2.0",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "*",
"clean-webpack-plugin": "^0.1.19",
"crypto-js": "^3.1.9-1",
"css-loader": "0.28.4",
"enzyme-to-json": "^3.3.4",
"event-source-polyfill": "0.0.9",
"extract-text-webpack-plugin": "2.1.2",
"file-loader": "0.11.2",
"file-saver": "^1.3.8",
"isomorphic-fetch": "2.2.1",
"jest": "^23.6.0",
"jquery": "^3.2.1",
"json-loader": "0.5.4",
"moment": "^2.22.2",
"raf": "^3.4.0",
"react": "^16.6.3",
"react-deep-force-update": "2.1.1",
"react-dom": "^16.6.3",
"react-hot-loader": "^4.0.0",
"react-router-dom": "4.1.1",
"react-select": "^2.0.0",
"style-loader": "0.18.2",
"ts-jest": "^23.10.3",
"ts-loader": "^2.0.1",
"typescript": "^2.9.2",
"url-loader": "0.5.9",
"webpack": "^4.15.1",
"webpack-cli": "^3.0.8",
"webpack-dev-middleware": "^3.1.3",
"webpack-hot-middleware": "^2.22.2"
EDIT: (adding boot.tsx and app.tsx to show hot module loading)
boot.tsx
import * as React from 'react';
import { runWithAdal } from 'react-adal';
import * as ReactDOM from 'react-dom';
import App from './app';
import { authContext } from './authentication/azure/azureConfig';
const DO_NOT_LOGIN = false;
function renderApp() {
ReactDOM.render(
<App />,
document.getElementById('react-app')
);
}
runWithAdal(authContext, () => {
renderApp();
}, DO_NOT_LOGIN);
app.tsx
import * as React from 'react';
import { hot } from 'react-hot-loader';
import { Provider } from 'react-redux';
import * as RoutesModule from './routes';
import { BrowserRouter } from 'react-router-dom';
import configureStore from './store/configureStore';
let routes = RoutesModule.routes;
const store = configureStore({});
const baseUrl =
document.getElementsByTagName('base')[0].getAttribute('href')!;
const App: React.SFC = () => <Provider store={store}>
;
export default hot(module)(App);
According to your above configuration, you're packing the js files into "wwwroot/dist/[name].js". The output information indicates that the Webpack hot reload feature is set up correctly. But it seems that Webpack has no idea on what the index page is. In other words, any changes made to *.tsx modules will only reload the compiled wwwroot/dist/main.js file.
For example, I create an App.tsx file:
import * as React from "react";
import * as ReactDOM from 'react-dom';
export const App = () => <div>Hello World!</div>
and render the App.tsx in the boot.tsx.
import * as React from "react";
import * as ReactDOM from 'react-dom';
import {App} from "./App";
ReactDOM.render(<App/>, document.getElementById("appconainer"));
When I serve the index page by MVC or StaticFiles, and then test with your configuration, Webpack won't know it should make a request to home/index action (or some "index.htm" url) to refresh.
A possible approach to fix
Since you've installed the react-hot-loader package, one approach is to use a hot() function to convert the root component to be hot-exported:
// file: `App.tsx`
import { hot } from 'react-hot-loader/root'
export const App = () => <div>Hello World!</div>
export const HotApp = hot(App); // make it hot-exported!
and render the hot-exported root component:
// file: root.tsx
import * as React from "react";
import * as ReactDOM from 'react-dom';
import {HotApp} from "./App"; // use the Hot-Exported component as the root component
ReactDOM.render(<App/>, document.getElementById("appconainer"));
For more details, see docs here

Vuejs hot reload Cannot read property 'Ctor' of undefined

I have this error when I update:
index.js:106 TypeError: Cannot read property 'Ctor' of undefined
at index.js:202
at Object.reload (index.js:104)
at reload (hot-reload.ts:17)
at router.ts:30
at hotApply (bootstrap 796061b879a4ebee3501:605)
at bootstrap 796061b879a4ebee3501:313
(anonymous) # index.js:106
reload # hot-reload.ts:17
(anonymous) # router.ts:30
hotApply # bootstrap 796061b879a4ebee3501:605
(anonymous) # bootstrap 796061b879a4ebee3501:313
Promise.then (async)
hotUpdateDownloaded # bootstrap 796061b879a4ebee3501:312
hotAddUpdateChunk # bootstrap 796061b879a4ebee3501:289
webpackHotUpdateCallback # bootstrap 796061b879a4ebee3501:31
(anonymous) # 10.796061b879a4ebee3501.hot-update.js:1
I tried to change versions for vue-bootstrap, webpack, hot-reload but I always have this error.
this is my package.json
{
"name": "v5",
"description": "MTN Project V5",
"version": "1.0.0",
"author": "ligadata-alaa <admhemed#gmail.com>",
"private": true,
"engines": {
"node": ">=6",
"npm": ">=3"
},
"scripts": {
"build": "cross-env-shell NODE_ENV=production npm run clean && npm run lint && npm run test && npm run compile",
"ci:teamcity": "karma --env=tc start config/karma.coverage.js && npm run coverage:remap",
"ci:jenkins": "karma --env=jk start config/karma.coverage.js && npm run coverage:remap",
"clean": "rimraf dist && rimraf coverage",
"compile": "webpack --config config/webpack.config.prod.js",
"coverage": "npm run coverage:run && npm run coverage:remap && npm run coverage:open",
"coverage:open": "opn coverage/html-ts/index.html",
"coverage:remap": "remap-istanbul -i coverage/json/coverage-final.json -o coverage/html-ts -t html",
"coverage:run": "cross-env NODE_ENV=development karma start config/karma.coverage.js",
"dev": "webpack-dev-server --config config/webpack.config.dev.js --hot --inline",
"lint": "tslint src/**/*.ts",
"serve": "http-server dist/ -g -o"
},
"dependencies": {
"axios": "~0.17.1",
"bootstrap-vue": "~2.0.0-rc.1",
"vue": "~2.5.13",
"vue-class-component": "~6.1.2",
"vue-property-decorator": "~6.0.0",
"vue-router": "~3.0.1"
},
"devDependencies": {
"#types/mocha": "~2.2.47",
"#types/node": "~9.4.0",
"#types/sinon": "~4.1.3",
"#types/webpack-env": "~1.13.5",
"autoprefixer": "~7.2.5",
"awesome-typescript-loader": "~3.4.1",
"bootstrap": "~4.0.0",
"chai": "~4.1.2",
"compression-webpack-plugin": "~1.1.6",
"copy-webpack-plugin": "~4.3.1",
"cross-env": "~5.1.3",
"css-hot-loader": "~1.3.6",
"css-loader": "~0.28.9",
"cssnano": "~3.10.0",
"es6-promise": "~4.2.4",
"eslint": "^5.4.0",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.0.0",
"eslint-plugin-standard": "^3.1.0",
"extract-text-webpack-plugin": "~3.0.2",
"favicons-webpack-plugin": "0.0.7",
"file-loader": "~1.1.6",
"html-webpack-plugin": "~2.30.1",
"http-server": "~0.11.1",
"istanbul-instrumenter-loader": "~3.0.0",
"json-loader": "~0.5.7",
"karma": "~2.0.0",
"karma-chai": "~0.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage": "~1.1.1",
"karma-junit-reporter": "~1.2.0",
"karma-mocha": "~1.3.0",
"karma-mocha-reporter": "~2.2.5",
"karma-sinon": "~1.0.5",
"karma-source-map-support": "~1.2.0",
"karma-sourcemap-loader": "~0.3.7",
"karma-teamcity-reporter": "~1.1.0",
"karma-webpack": "~2.0.9",
"lodash.merge": "~4.6.0",
"minimist": "~1.2.0",
"mocha": "~5.0.0",
"ncp": "~2.0.0",
"node-sass": "~4.7.2",
"opn-cli": "~3.1.0",
"optimize-css-assets-webpack-plugin": "~3.2.0",
"postcss-loader": "^2.0.10",
"raw-loader": "~0.5.1",
"remap-istanbul": "~0.10.1",
"rimraf": "~2.6.2",
"sass-loader": "~6.0.6",
"sinon": "~4.2.2",
"standard": "~10.0.3",
"style-loader": "~0.20.1",
"tslint": "~5.9.1",
"tslint-config-standard": "~7.0.0",
"tslint-loader": "~3.5.3",
"typescript": "~2.7.1",
"url-loader": "~0.6.2",
"vue-cli-plugin-vuetify": "^0.1.6",
"vue-hot-reload-api": "~2.2.4",
"webpack": "~3.10.0",
"webpack-dev-server": "~2.11.1"
}
}
main.ts
import Vue from 'vue';
import { makeHot, reload } from './util/hot-reload';
import {router} from './router';
import store from './store/index';
const navbarComponent = () => import('./components/navbar').then(({ NavbarComponent }) => NavbarComponent);
const sidebarComponent = () => import('./components/sidebar').then(({ SidebarComponent }) => SidebarComponent);
const bottombarComponent = () => import('./components/bottombar').then(({ BottombarComponent }) => BottombarComponent);
// const navbarComponent =
// () => import(/* webpackChunkName: 'navbar' */'./components/navbar').then(({ NavbarComponent }) => NavbarComponent)
import './sass/main.scss';
import VueResource from 'vue-resource';
Vue.use(VueResource);
if (process.env.ENV === 'development' && module.hot) {
const navbarModuleId = './components/navbar';
// first arguments for `module.hot.accept` and `require` methods have to be static strings
// see https://github.com/webpack/webpack/issues/5668
makeHot(navbarModuleId, navbarComponent,
module.hot.accept('./components/navbar',
() => reload(navbarModuleId, (require('./components/navbar') as any).NavbarComponent)));
}
// tslint:disable-next-line:no-unused-expression
export const VueApp = new Vue({
el: '#app-main',
router,
store,
http: {
root: ''
},
components: {
navbar: navbarComponent,
sidebar: sidebarComponent,
bottombar: bottombarComponent
}
});
Vue.config.productionTip = false;
router.ts
import Vue from 'vue';
import VueRouter, { Location, Route, RouteConfig } from 'vue-router';
import { makeHot, reload } from './util/hot-reload';
import store from './store/index';
const homeComponent = () => import('./components/home').then(({ HomeComponent }) => HomeComponent);
const aboutComponent = () => import('./components/about').then(({ AboutComponent }) => AboutComponent);
const htmlComponent = () => import('./components/html').then(({ HtmlComponent }) => HtmlComponent);
const gridComponent = () => import('./components/grid').then(({ GridComponent }) => GridComponent);
// const homeComponent = () =>
// import(/* webpackChunkName: 'home' */'./components/home').then(({ HomeComponent }) => HomeComponent)
// const aboutComponent = () =>
// import(/* webpackChunkName: 'about' */'./components/about').then(({ AboutComponent }) => AboutComponent)
// const listComponent = () =>
// import(/* webpackChunkName: 'list' */'./components/list').then(({ ListComponent }) => ListComponent)
if (process.env.ENV === 'development' && module.hot) {
const homeModuleId = './components/home';
const htmlModuleId = './components/html';
const gridModuleId = './components/grid';
const aboutModuleId = './components/about';
// first arguments for `module.hot.accept` and `require` methods have to be static strings
// see https://github.com/webpack/webpack/issues/5668
makeHot(homeModuleId, homeComponent,
module.hot.accept('./components/home',
() => reload(homeModuleId, (require('./components/home') as any).HomeComponent)));
makeHot(homeModuleId, gridComponent,
module.hot.accept('./components/grid',
() => reload(gridModuleId, (require('./components/grid') as any).GridComponent)));
makeHot(aboutModuleId, htmlComponent,
module.hot.accept('./components/about',
() => reload(aboutModuleId, (require('./components/about') as any).AboutComponent)));
makeHot(aboutModuleId, aboutComponent,
module.hot.accept('./components/about',
() => reload(aboutModuleId, (require('./components/about') as any).AboutComponent)));
}
Vue.use(VueRouter);
export const createRoutes: () => RouteConfig[] = () => [
{
path: '/',
component: homeComponent
},
{
path: '/home',
component: homeComponent
},
{
path: '/grid',
component: gridComponent
},
{
path: '/html',
component: htmlComponent
},
{
path: '/about',
component: aboutComponent
}
];
export const createRouter = () => new VueRouter({ mode: 'history', routes: createRoutes() });
export const router = createRouter();
router.afterEach((to, from) => {
if (to.path === '/grid') {
store.dispatch('search/checkIfThereIsASearch', []);
}
});
I got over it just by refreshing the page.
If you have changed the versions
try clearing node modules
reinstall/update npm modules
this will ensure all modules are new and correctly installed
Please upgrade vue-loader to 15.7.1. This PR should fix it.

Import vue package in laravel

What is the corect way to import vue packages in laravel 5.6? It comes with vue and bootstrap preinstall. I see they are all compile in app.js from public directory but I can figure out how to import https://github.com/moreta/vue-search-select and use it. After I tried to import it on my own:
Error:
ncaught TypeError: Vue.component is not a function
At line:
Vue.component('search-user', __webpack_require__(42));
Until now I tried this:
assets/js/bootstrap.js:
import { BasicSelect } from 'vue-search-select';
window.BasicSelect = BasicSelect;
assets/js/app.js:
require('./bootstrap');
window.Vue = require('vue');
window.Vue = require('vue-search-select');
Vue.component('search-user', require('./components/SearchUser.vue'));
var app = new Vue({
el: '#app'
})
components
<template>
<basic-select :options="options"
:selected-option="item"
placeholder="select item"
#select="onSelect">
</basic-select>
</template>
<script>
export default {
data() {
return {
keywords: null,
options: []
};
},
watch: {
keywords(after, before) {
if (this.keywords.length > 0)
this.fetch();
}
},
methods: {
fetch() {
axios.get('/api/search', {params: {keywords: this.keywords}})
.then(response => this.options = response.data)
.catch(error => {
});
},
onSelect (item) {
this.item = item
},
reset () {
this.item = {}
},
selectOption () {
// select option from parent component
this.item = this.options[0]
},
components: {
BasicSelect
}
}
}
</script>
I ran: npm install and npm run watch:
"devDependencies": {
"ajv": "^6.0.0",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"laravel-mix": "^2.0",
"lodash": "^4.17.4",
"popper.js": "^1.12",
"uikit": "^3.0.0-beta.35",
"vue": "^2.5.7",
"vue-search-select": "^2.5.0"
},
"dependencies": {
"axios": "^0.17.1",
"jquery": "^3.3.1"
}
I think that the simple will do
window.Vue = require('vue');
require('vue-search-select');
Then in your components you can import what you need on top:
import { BasicSelect } from 'vue-search-select';
export default {
data() {
return {
keywords: null,
options: [],
item: null
};
},
...
One missing detail that tricked me with this one, you need to register the components like this, otherwise it won't be found:
components: {
ModelSelect,
BasicSelect
},