Vue 3, Ionic 6 menu component shows black screen - vue.js

Project was setup using Ionic's CLI, nothing custom, except some linter configs.
The problem: every time i try to use IonMenu, it just breaks the whole page.
Page Component:
<template>
<ion-page>
<ion-menu
side="start"
content-id="menuContent"
>
<ion-header>
<ion-toolbar color="secondary">
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-label>START MENU CONTENTS</ion-label>
</ion-content>
</ion-menu>
<ion-router-outlet id="menuContent" />
</ion-page>
</template>
<script>
import {
IonPage,
IonRouterOutlet,
IonContent,
IonHeader,
IonMenu,
IonTitle,
IonToolbar
} from '#ionic/vue';
import { defineComponent } from 'vue';
export default defineComponent({
name: 'index-page',
components: {
IonPage,
IonRouterOutlet,
IonContent,
IonHeader,
IonMenu,
IonTitle,
IonToolbar
}
});
</script>
Result (it's identical in browser and in emulator): nested menu content renders, but the page looks like this
If I remove <ion-menu> component, everything works just fine
My package.json
{
"name": "notes",
"version": "0.0.1",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"test:e2e": "vue-cli-service test:e2e",
"lint:eslint": "./node_modules/.bin/eslint -c .eslintrc.js .",
"lint:eslint:fix": "npm run lint:eslint -- --fix",
"lint:stylelint": "./node_modules/.bin/stylelint --config stylelint.config.js .",
"lint:stylelint:fix": "npm run lint:stylelint -- --fix"
},
"dependencies": {
"#capacitor/app": "1.1.1",
"#capacitor/core": "3.5.1",
"#capacitor/haptics": "1.1.4",
"#capacitor/keyboard": "1.2.2",
"#capacitor/status-bar": "1.0.8",
"#ionic/vue": "6.0.0",
"#ionic/vue-router": "6.0.0",
"core-js": "3.6.5",
"vue": "3.2.21",
"vue-router": "4.0.12"
},
"devDependencies": {
"#capacitor/cli": "3.5.1",
"#types/jest": "27.0.2",
"#typescript-eslint/eslint-plugin": "5.6.0",
"#typescript-eslint/parser": "5.6.0",
"#vue/cli-plugin-babel": "~5.0.0-rc.1",
"#vue/cli-plugin-e2e-cypress": "~5.0.0-rc.1",
"#vue/cli-plugin-eslint": "~5.0.0-rc.1",
"#vue/cli-plugin-router": "~5.0.0-rc.1",
"#vue/cli-plugin-typescript": "~5.0.0-rc.1",
"#vue/cli-plugin-unit-jest": "~5.0.0-rc.1",
"#vue/cli-service": "~5.0.0-rc.1",
"#vue/eslint-config-typescript": "9.1.0",
"#vue/test-utils": "2.0.0-rc.16",
"#vue/vue3-jest": "27.0.0-alpha.3",
"#vuebits/bem": "1.2.2",
"babel-jest": "27.3.1",
"cypress": "8.7.0",
"eslint": "8.4.1",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-unused-imports": "2.0.0",
"eslint-plugin-vue": "8.2.0",
"jest": "27.3.1",
"npm-run-all": "4.1.5",
"sass": "1.52.2",
"sass-loader": "13.0.0",
"stylelint": "13.13.1",
"stylelint-config-rational-order": "0.1.2",
"stylelint-config-standard": "22.0.0",
"stylelint-order": "4.1.0",
"stylelint-webpack-plugin": "2.1.1",
"ts-jest": "27.0.7",
"typescript": "4.3.5",
"vue-auto-routing": "1.0.1",
"vue-eslint-parser": "9.0.2"
},
"description": "An Ionic project"
}
My vue.config.js
const VueAutoRoutingPlugin = require('vue-auto-routing/lib/webpack-plugin');
const { definePlugin } = require('./config/webpack/define-plugin');
const { linterPlugins } = require('./config/webpack/linter-plugins');
const { getWebpackAliases } = require('./config/webpack/aliases');
module.exports = {
configureWebpack: config => {
config.stats = 'normal';
const routerPlugin = new VueAutoRoutingPlugin({
pages: 'src/pages',
importPrefix: '~/src/pages/'
});
config.plugins = config.plugins.concat([definePlugin, routerPlugin]);
if (process.env.LINT_ON_BUILD === 'true') {
plugins.push(...linterPlugins);
}
config.resolve.alias = { ...config.resolve.alias, ...getWebpackAliases() };
}
};

Related

SyntaxError: Cannot use import statement outside a module in jest

I would like to do vue util test using jest, but since i used import statement, it keeps making errors.
it says "SyntaxError: Cannot use import statement outside a module "
" at ScriptTransformer._transformAndBuildScript (node_modules/#jest/transform/build/ScriptTransformer.js:537:17)"
i've tried adding type:module to my package.json, transformIgnorePatterns to jest.config.js , and module to my script tag. none of them worked. i think it is related to version, as i am using vue 2 to get track of lessons im listening to. please take a look at my code
this is my package.json
{
"name": "jest-test",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^1.2.3",
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vuex": "^3.4.0"
},
"devDependencies": {
"#babel/preset-env": "^7.20.2",
"#vue/cli-plugin-babel": "^4.1.2",
"#vue/cli-plugin-eslint": "^4.1.2",
"#vue/cli-plugin-unit-jest": "^4.1.2",
"#vue/cli-plugin-vuex": "^4.1.2",
"#vue/cli-service": "^4.1.2",
"#vue/eslint-config-standard": "^5.1.2",
"#vue/test-utils": "^1.0.3",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^6.2.2",
"node-sass": "^4.12.0",
"sass-loader": "^8.0.2",
"vue-template-compiler": "^2.6.11"
}
}
this is my error code to test
<template>
<div>
{{ todo.title }}
</div>
</template>
<script>
import axios from "axios";
export default {
data() {
return {
todo: {},
};
},
created() {
this.fetchTodo();
},
methods: {
async fetchTodo() {
const { data } = await axios.get(
"https://jsonplaceholder.typicode.com/todos/1"
);
this.todo = data;
},
},
};
</script>
and this is testing code
import { shallowMount } from "#vue/test-utils";
import TodoTitle from "#/components/TodoTitle";
describe("TodoTitle Component", () =\> {
test("rendering", () =\> {
const wrapper = shallowMount(TodoTitle);
console.log(wrapper);
expect(wrapper.text()).toBe("");
});
});

vue quasar JSX Failed to resolve component

I have the following code:
Tmp1Component.tsx
import { h, defineComponent } from 'vue'
export default defineComponent({
name: 'App',
setup () {
const x = "test"
},
render() {
return [<q-btn>Test</q-btn>,<div>Tes2</div>]
}}
)
Tmp1Page.vue
<template>
<tmp1-component />
<tmp2-component />
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
import Tmp1Component from '../components/Tmp1Component.tsx'
import Tmp2Component from '../components/Tmp2Component.vue'
export default defineComponent({
name: 'Tmp1Page',
inheritAttrs: false,
components: { Tmp1Component, Tmp2Component },
setup () {
{}
}
});
</script>
babel.config.js
module.exports = {
presets: [
'#vue/cli-plugin-babel/preset'
// '#quasar/babel-preset-app'
],
plugins: ["#vue/babel-plugin-jsx", "transform-vue-jsx"]
}
package.json
{
"name": "kitty",
"version": "0.0.1",
"private": true,
"description": "Kitty desc",
"author": "amirny2205 <*.ru>",
"scripts": {
"lint": "eslint --ext .js,.ts,.vue ./",
"format": "prettier --write \"**/*.{js,ts,vue,scss,html,md,json}\" --ignore-path .gitignore",
"test": "echo \"No test specified\" && exit 0"
},
"dependencies": {
"#quasar/extras": "^1.0.0",
"#vitejs/plugin-vue-jsx": "^3.0.0",
"#vue/babel-plugin-jsx": "^1.1.1",
"#vue/cli-plugin-babel": "^5.0.8",
"axios": "^0.21.1",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-vue-jsx": "^3.7.0",
"core-js": "^3.8.3",
"jquery": "^3.6.3",
"pinia": "^2.0.11",
"quasar": "^2.6.0",
"vue": "^3.0.0",
"vue-i18n": "^9.2.2",
"vue-router": "^4.0.0"
},
"devDependencies": {
"#intlify/vite-plugin-vue-i18n": "^3.3.1",
"#quasar/app-vite": "^1.0.0",
"#types/node": "^12.20.21",
"#typescript-eslint/eslint-plugin": "^5.10.0",
"#typescript-eslint/parser": "^5.10.0",
"autoprefixer": "^10.4.2",
"eslint": "^8.10.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-vue": "^9.0.0",
"prettier": "^2.5.1",
"typescript": "^4.5.4",
"vite": "^3"
},
"engines": {
"node": "^18 || ^16 || ^14.19",
"npm": ">= 6.13.4",
"yarn": ">= 1.21.1"
},
"productName": "Kitty"
}
And I am getting "Failed to resolve component: q-btn"
screenshot
JSX works as you can see by the "test" string
Quasar components work as you can see by "BUTN"
I have found this: https://github.com/quasarframework/quasar/issues/7672
( https://codesandbox.io/s/magical-dew-mybq9?file=/package.json )
and this:
https://codesandbox.io/s/53ki6?file=/src/App.tsx
Both work in the sandbox though I cannot get them to work locally
The solution was to import the component in quasar.config.js

setting up apollo graphql-tag loader issue in vue js

I am new to graphql and I have been getting this error when trying to use .graphql file inside vue apollo. while using gql tag , it works fine , but while importing graphql file this error is showing up.
i have tried to use graphql loader but it doesnt seems to be working.
Failed to resolve loader: cache-loader
You may need to install it.
ERROR in ./src/client/pages/Clients.vue?vue&type=script&lang=js&
(./node_modules/babel-loader/lib/index.js??clonedRuleSet-
40.use[0]!./node_modules/#vue/cli-service/lib/config/vue-loader-v15-resolve-
compat/vue-loader.js??vue-loader-options!./src/client/pages/Clients.vue?
vue&type=script&lang=js&) 100:15-55
Module not found: Error: Can't resolve 'cache-loader' in '/home/noakash/temp/gym-
client'
# ./src/client/pages/Clients.vue?vue&type=script&lang=js& 1:0-246 1:262-265 1:267- 510 1:267-510
# ./src/client/pages/Clients.vue 2:0-59 3:0-54 3:0-54 9:2-8
# ./src/router/index.js 5:0-50 31:13-20
# ./src/main.js 3:0-30 18:2-8
webpack compiled with 1 error
my Clients.vue file look like this
apollo: {
clients() {
return {
query:require('../../graphql/clients.graphql'),
result({ loading }) {
this.loading = loading;
},
};
},
},
i am using vue-cli
my vue.config.js look like this
const { defineConfig } = require('#vue/cli-service')
module.exports = defineConfig({
configureWebpack:{
module:{
rules:[
{
test: /\.graphql$/,
use: 'graphql-tag/loader'
}
]
}
},
transpileDependencies: [
'vuetify'
],
})
my package.json
{
"name": "gym-client",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"apollo": "vue-cli-service apollo:dev --generate-schema",
"apollo:schema:generate": "vue-cli-service apollo:schema:generate",
"apollo:schema:publish": "vue-cli-service apollo:schema:publish",
"apollo:start": "vue-cli-service apollo:start"
},
"dependencies": {
"apollo-boost": "^0.4.9",
"apollo-cache-inmemory": "^1.6.6",
"apollo-client": "^2.6.10",
"apollo-link": "^1.2.14",
"apollo-link-http": "^1.5.17",
"core-js": "^3.25.0",
"graphql": "^15.8.0",
"graphql-tag": "^2.12.6",
"jspdf": "^2.5.1",
"lowdb": "^1.0.0",
"mkdirp": "^0.5.1",
"moment": "^2.29.4",
"regenerator-runtime": "^0.13.9",
"shortid": "^2.2.8",
"vue": "^2.6.14",
"vue-apollo": "^3.1.0",
"vue-router": "^3.5.1",
"vuetify": "^2.6.0",
"vuex": "^3.6.2"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~5.0.0",
"#vue/cli-plugin-router": "~5.0.0",
"#vue/cli-plugin-vuex": "~5.0.0",
"#vue/cli-service": "~5.0.0",
"sass": "~1.32.0",
"sass-loader": "^10.0.0",
"vue-cli-plugin-apollo": "~0.22.2",
"vue-cli-plugin-vuetify": "~2.5.5",
"vue-template-compiler": "^2.6.14",
"vuetify-loader": "^1.7.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}

vue3-electron production build facing webpackJsonp not defined problem

I'm trying to build an electron app from a vue-cli3 project. The vue project itself works fine both in development and production. Everything works as well if I run a dev mode with npm run electron:serve. But the built electron app would give a Uncaught TypeError: Cannot read property 'webpackJsonp' of undefined in each packed js file.
vue.config.js:
module.exports = {
configureWebpack: config => {
const tsLoader = config.module.rules.find((loader) => loader.test === /\.ts$/);
const tsLoaderIndex = config.module.rules.indexOf(tsLoader);
const webWorkerLoader = {
test: /\.worker\.ts$/,
use: [
{
loader: 'worker-loader',
options: {
filename: 'WorkerName.[hash].js',
inline: 'fallback',
}
}
]
}
config.module.rules = [...config.module.rules.slice(0, tsLoaderIndex-1), webWorkerLoader, ...config.module.rules.slice(tsLoaderIndex-1)]
// console.log(config.module.rules);
if (process.env.NODE_ENV === 'production') {
config.mode = 'production'
// pack dependencies separately
let optimization = {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 20000,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name (module) {
// get the name. E.g. node_modules/packageName/not/this/part.js
// or node_modules/packageName
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
// npm package names are URL-safe, but some servers don't like # symbols
return `npm.${packageName.replace('#', '')}`
}
}
}
}
}
Object.assign(config, {
optimization
})
}
},
parallel: false,
chainWebpack: config => {
config.output.globalObject('this')
},
pluginOptions: {
'style-resources-loader': {
preProcessor: 'scss',
patterns: []
}
},
css: {
loaderOptions: {
less: {
lessOptions: {
modifyVars: {
'font-size-base': '18px'
},
javascriptEnabled: true
}
}
}
},
devServer: {
host: '127.0.0.1',
port: 8080,
public: 'localhost:8080',
}
}
package.json:
{
"name": "testApp",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
"main": "background.js",
"dependencies": {
"#ant-design/icons-vue": "^6.0.1",
"#kyvg/vue3-notification": "^2.3.4",
"ant-design-vue": "^2.2.8",
"bioseq": "^0.1.5",
"core-js": "^3.6.5",
"echarts": "^5.3.3",
"idb-keyval": "^5.1.3",
"jszip": "^3.7.1",
"lodash": "^4.17.21",
"pako": "^1.0.11",
"pdfmake": "^0.2.5",
"vue": "^3.2.4",
"vue3-infinite-scroll-good": "^1.0.2",
"xlsx": "^0.17.2"
},
"devDependencies": {
"#babel/core": "^7.14.6",
"#babel/preset-env": "^7.14.7",
"#babel/preset-react": "^7.14.5",
"#types/electron-devtools-installer": "^2.2.0",
"#types/node": "^16.0.0",
"#types/pako": "^1.0.2",
"#types/pdfmake": "^0.2.1",
"#typescript-eslint/eslint-plugin": "^4.18.0",
"#typescript-eslint/parser": "^4.18.0",
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-plugin-typescript": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"#vue/compiler-sfc": "^3.1.4",
"#vue/eslint-config-typescript": "^7.0.0",
"electron": "^13.6.9",
"electron-devtools-installer": "^3.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^7.0.0",
"less": "^4.1.2",
"less-loader": "^7.3.0",
"style-resources-loader": "^1.4.1",
"typescript": "~4.1.5",
"vue-cli-plugin-electron-builder": "~2.1.1",
"vue-cli-plugin-style-resources-loader": "~0.1.5",
"worker-loader": "^3.0.8"
}
}
There are some instructions that it may be caused by something wrong with the webpack configuration. But I can only find examples in vue-cli2 webpack.prod.conf.js. How do we modify that in vue-cli3?
Find the clue at https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/1706
There was a mistype 'this' in one of my vue templates causing the error. Removing that fixed the problem.

when i am trying to run test cases it shows me shallowMount error,How to fix ShallowMount error in VUE.JS?

i am wrighting test cases for LoginNew.vue component , when i am trying to import that component inside the spec.js file i am getting shallowMount error [check my error here] ,i don't know why i am getting this error please help me to fix this issue
jest.config.js
module.exports = {
moduleNameMapper:{
"~(.*)$": "<rootDir>/resources/js/$1",
},
setupFilesAfterEnv: ['<rootDir>resources/src/tests/setup.js'],
resolver: require.resolve(`jest-pnp-resolver`),
testEnvironment: `node`,
};
LoginNew.vue
<template>
<div>
<h1 id="title">Login</h1>
<input type="text" id="input-username"/>
<input type="password" id="input-password"/>
<button id="btn-sign-in">Sign In</button>
</div>
</template>
<script>
export default {
name: 'LoginNew'
}
</script>
Login.spec.js
import LoginNew from '../../src/Pages/LoginNew.vue';
import{shallowMount} from '#vue/test-utils';
describe('LoginNew.vue',()=>{
describe('When Loaded',()=>{
it('has the required elements',()=>{
const wrapper =shallowMount(LoginNew);
expect(wrapper.find('#input-username').exists()).toBe(false);
expect(wrapper.find('#input-password').exists()).toBe(false);
});
});
});
package.json
{
"name": "vue-fundoo",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve --port 3000",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"test": "jest"
},
"dependencies": {
"#vue/composition-api": "^1.0.0-rc.9",
"#vuelidate/core": "^2.0.0-alpha.18",
"#vuelidate/validators": "^2.0.0-alpha.15",
"axios": "^0.21.1",
"bootstrap": "^5.0.1",
"core-js": "^3.6.5",
"dotenv": "^10.0.0",
"jquery": "^3.6.0",
"vue": "^2.6.11",
"vue-axios": "^3.2.4",
"vue-router": "^3.5.1",
"vue-template-compiler": "^2.6.12",
"vuelidate": "^0.7.6"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"#vue/test-utils": "^1.2.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^27.0.2",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"jest": "^27.0.3",
"node-sass": "^5.0.0",
"sass": "^1.19.0",
"sass-loader": "^10.1.1",
"vue-jest": "^3.0.7",
"vue-test-utils": "^1.0.0-beta.11",
"webpack": "^4.0.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
],
"jest": {
"transform": {
"^.+\\.vue$": "vue-jest",
"^.+\\.js$": "babel-jest"
}
}
}
Update the jest configuration to
testEnvironment: 'jsdom'
The defaults has been changed for Jest 27
Read more about it here.
https://jestjs.io/blog/2021/05/25/jest-27