use async \ await in vue? - vue.js

I want to use async \ await in Vue.
there is order-list.vue, in short methods this is:
getOrder: function () {
return new Promise(function (resolve, reject) {
setTimeout(() => {
console.log('hello world');
resolve(true)
}, 2000)
});
},
example: async() => {
console.log('start');
for (let i in this.orders) {
await this.getOrder().then(
console.log('loaded ' + i)
)
}
console.log('finish');
}
it's all going to webpack.
When I start webpack, I get this message
ERROR in ./erp/vue/order-list.vue?vue&type=script&lang=js& (./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./erp/vue/order-list.vue?vue&type=script&lang=js&)
Module not found: Error: Can't resolve '#babel/runtime/regenerator' in '/Users/pankovalxndr/Sites/mysite/erp/vue'
# ./erp/vue/order-list.vue?vue&type=script&lang=js& (./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./erp/vue/order-list.vue?vue&type=script&lang=js&) 1:0-61 141:13-32 146:28-47 156:21-40
package.json
What is wrong here?
"devDependencies": {
"#babel/core": "^7.4.3",
"#babel/plugin-transform-runtime": "^7.6.2",
"#babel/preset-env": "^7.4.3",
"autoprefixer": "^8.6.5",
"babel-loader": "^8.0.0-beta.6",
"babel-runtime": "^6.26.0",
"gulp": "git://github.com/gulpjs/gulp.git#6d71a658c61edb3090221579d8f97dbe086ba2ed",
"gulp-cheerio": "^0.6.3",
"gulp-cssnano": "^2.1.2",
"gulp-postcss": "^7.0.1",
"gulp-print": "^5.0.2",
"gulp-rename": "^1.4.0",
"gulp-replace": "^0.6.1",
"gulp-sass": "^3.1.0",
"gulp-svg-sprite": "^1.5.0",
"gulp-svgmin": "^1.2.4",
"gulp-uglify": "^3.0.2",
"gulp-watch": "^5.0.1",
"vue-loader": "^15.7.2",
"vue-style-loader": "^4.1.2",
"vue-template-compiler": "^2.5.17",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0"
}
My .babelrc
What is wrong here?
{
"presets": [
"#babel/preset-env"
],
"plugins": [
[
"#babel/plugin-transform-runtime",
{
"regenerator": true
}
]
]
}
webpack file
What is wrong here?
module: {
rules: [
{
test: /\.vue$/,
use: 'vue-loader'
},
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
]
}, {
test: /\.js$/,
use: 'babel-loader'
}
]
},
plugins: [
new VueLoaderPlugin(),
]
If I remove functions with await then everything starts to work well, those things are not specifically, more precisely in some module

Related

Vue v2.7 & Pinia v2.0.22 throwing devtools-api error during build

Here is my dependency tree:
"dependencies": {
"#s-r0/eggy-js": "^1.3.4",
"#shopify/theme-predictive-search": "^4.0.0",
"#splidejs/vue-splide": "^0.5.18",
"axios": "^0.21.1",
"carousel-carousel": "^0.1.24",
"embla-carousel": "^2.9.1",
"eslint-config-prettier": "^6.12.0",
"eslint-plugin-prettier": "^3.1.4",
"lazysizes": "^5.2.2",
"module-name": "^0.0.1-security",
"pinia": "^2.0.22",
"v-tooltip": "^2.0.3",
"vendor": "^1.7.0",
"vue": "^2.7",
"vue-click-outside-element": "^1.0.15",
"vue-scrollto": "^2.20.0",
"vue2-transitions": "^0.3.0",
"vuejs-datepicker": "^1.6.2"
},
"devDependencies": {
"#babel/core": "^7.10.1",
"#babel/plugin-transform-destructuring": "^7.10.1",
"#babel/plugin-transform-object-assign": "^7.10.1",
"#babel/plugin-transform-runtime": "^7.10.1",
"#babel/preset-env": "^7.10.1",
"#shopify/eslint-plugin": "^39.0.1",
"#shopify/stylelint-plugin": "^10.0.1",
"#shopify/themekit": "~1.1.4",
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-unit-jest": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"#vue/test-utils": "^1.0.3",
"babel-loader": "^8.1.0",
"babel-plugin-dynamic-import-node": "^2.3.3",
"browser-sync": "^2.26.7",
"concurrently": "^5.2.0",
"copyfiles": "^2.3.0",
"css-loader": "^4.2.0",
"cssnano": "^4.1.10",
"eslint": "^7.11.0",
"eslint-plugin-vue": "^9.0.0",
"file-loader": "^6.0.0",
"jest-vue-preprocessor": "^1.7.1",
"node-watch": "^0.6.4",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"rimraf": "^3.0.2",
"sass": "^1.26.7",
"sass-loader": "^8.0.2",
"stylelint": "^13.7.2",
"stylelint-order": "^4.1.0",
"vue-loader": "^15.10.0",
"vue-template-compiler": "^2.6.11",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
}
I can install my dependencies with either NPM or yarn just fine. However, when I run my script for webpack to bundle everything, I keep getting the error:
ERROR in ./node_modules/pinia/dist/pinia.mjs
Module not found: Error: Can't resolve '#vue/devtools-api' in '/Users/gabe/Documents/GitHub/hive-brands/node_modules/pinia/dist'
# ./node_modules/pinia/dist/pinia.mjs 7:0-56 505:4-23 709:4-23
# ./src/vue/theme.js
# ./src/scripts/theme.js
# multi ./src/scripts/theme.js ./src/styles/theme.scss
Here is my webpack config just in case:
const path = require("path");
const VueLoaderPlugin = require("vue-loader/lib/plugin");
const webpackConfig = {
mode: "production",
resolve: {
alias: {
"#scripts": path.resolve(__dirname, "src/vue"),
"#vue": path.resolve(__dirname, "src/vue")
}
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.vue$/,
loader: "vue-loader"
},
{
test: /theme.scss/,
exclude: /node_modules/,
use: [
{
loader: "file-loader",
options: { name: "theme.min.css" }
},
"sass-loader"
]
},
{
test: /checkout.scss/,
exclude: /node_modules/,
use: [
{
loader: "file-loader",
options: { name: "checkout.min.css" }
},
"sass-loader"
]
},
{
test: /\.mjs$/,
include: /node_modules/,
type: "javascript/auto"
}
]
},
plugins: [new VueLoaderPlugin()]
};
const themeConfig = {
...webpackConfig,
name: "theme",
entry: [
`${__dirname}/src/scripts/theme.js`,
`${__dirname}/src/styles/theme.scss`
],
output: {
path: path.join(__dirname, "src/assets"),
filename: "theme.min.js"
}
};
const checkoutConfig = {
...webpackConfig,
name: "checkout",
entry: [
`${__dirname}/src/scripts/checkout.js`,
`${__dirname}/src/styles/checkout.scss`
],
output: {
path: path.join(__dirname, "src/assets"),
filename: "checkout.min.js"
}
};
module.exports = [themeConfig, checkoutConfig];

Rails Vue2 Jest SyntaxError: Cannot use import statement outside a module

I have a Rails application with Vue and when I installed Jest and tried to run my Menu_Filter.test.js test, I got this error. I tried many solutions, but nothing worked.
Error:
My package.json in which I configured Jest:
{
"name": "immomapper-frontend",
"version": "0.1.0",
"dependencies": {
"#rails/actioncable": "^6.0.0",
"#rails/activestorage": "^6.0.0",
"#rails/ujs": "^6.0.0",
"#rails/webpacker": "5.4.3",
"#vue/composition-api": "^1.2.4",
"#vueform/multiselect": "^2.2.0",
"#vueform/slider": "^2.0.5",
"babel": "^6.23.0",
"babel-jest": "^27.2.5",
"jest": "^27.2.5",
"leaflet": "^1.7.1",
"turbolinks": "^5.2.0",
"vue": "^2.6.14",
"vue-loader": "^15.9.8",
"vue-template-compiler": "^2.6.14",
"vue2-leaflet": "^2.7.1",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
},
"devDependencies": {
"#babel/core": "^7.15.8",
"#babel/preset-env": "^7.15.8",
"#vue/babel-preset-app": "^4.5.14",
"#vue/cli-plugin-unit-jest": "~4.5.0",
"#vue/test-utils": "^1.2.2",
"babel-core": "^7.0.0-bridge.0",
"vue-jest": "^3.0.7",
"webpack-dev-server": "^3"
},
"scripts": {
"test": "jest"
},
"jest": {
"roots": [
"app/javascript/spec"
],
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"moduleNameMapper": {
"^#/(.*)$'": "<rootDir>/src/$1"
},
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue-jest"
},
"testEnvironment": "jsdom"
}
}
My test file:
import { mount, shallowMount } from '#vue/test-utils'
import Filter from '../components/Menu_filter'
test('Filter exists', () => {
const wrapper = mount(Filter);
expect(wrapper.is(Filter)).toBe(true)
})
Lastly, my babel.config.js:
module.exports = function(api) {
var validEnv = ['development', 'test', 'production']
var currentEnv = api.env()
var isDevelopmentEnv = api.env('development')
var isProductionEnv = api.env('production')
var isTestEnv = api.env('test')
if (!validEnv.includes(currentEnv)) {
throw new Error(
'Please specify a valid `NODE_ENV` or ' +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' +
JSON.stringify(currentEnv) +
'.'
)
}
return {
presets: [
isTestEnv && [
'#babel/preset-env',
{
targets: {
node: 'current'
}
}
],
(isProductionEnv || isDevelopmentEnv) && [
'#babel/preset-env',
{
forceAllTransforms: true,
useBuiltIns: 'entry',
corejs: 3,
modules: auto,
exclude: ['transform-typeof-symbol']
}
]
].filter(Boolean),
plugins: [
'babel-plugin-macros',
'#babel/plugin-syntax-dynamic-import',
isTestEnv && 'babel-plugin-dynamic-import-node',
'#babel/plugin-transform-destructuring',
[
'#babel/plugin-proposal-class-properties',
{
loose: true
}
],
[
'#babel/plugin-proposal-object-rest-spread',
{
useBuiltIns: true
}
],
[
'#babel/plugin-proposal-private-methods',
{
loose: true
}
],
[
'#babel/plugin-proposal-private-property-in-object',
{
loose: true
}
],
[
'#babel/plugin-transform-runtime',
{
helpers: false
}
],
[
'#babel/plugin-transform-regenerator',
{
async: false
}
]
].filter(Boolean)
}
}
I don't use Typescript, I did add the yarn add babel-core#bridge --dev, I used transform, I also tried to change the jest version to 26.x.x, I added type="module" to my vue component... I don't know what the problem is.

How to configure Tailwind + Postcss with VueJS in Laravel InertiaJS

I am new to setting up the tailwind/postcss configuration using Intertia.js/Vue.js and would appreciate some guidance with my configuration files!
My goal is to be able to write postcss/scss style within my vue components, with the ability to use the postcss #apply functionality for example, like so:
Navigation.vue:
<style lang="postcss">
.nav-items {
#apply bg-red;
}
</style>
With the current configuration setup I have, I am not getting any errors compiling however the style is not being applied, it doesn't appear in the Styles in console for the element.
webpack.mix.js
const mix = require('laravel-mix')
const path = require('path')
const purgecss = require('#fullhuman/postcss-purgecss')
const tailwindcss = require('tailwindcss')
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css/app.css')
.options({
postCss: [
tailwindcss('tailwind.config.js'),
...mix.inProduction() ? [
purgecss({
content: ['./resources/views/**/*.blade.php', './resources/js/**/*.vue'],
defaultExtractor: content => content.match(/[\w-/:.]+(?<!:)/g) || [],
whitelistPatternsChildren: [/nprogress/],
}),
] : [],
],
})
.webpackConfig({
output: { chunkFilename: 'js/[name].js?id=[chunkhash]' },
resolve: {
alias: {
vue$: 'vue/dist/vue.runtime.js',
'#': path.resolve('resources/js'),
ziggy: path.resolve('vendor/tightenco/ziggy/src/js/route.js'),
},
},
module: {
rules: [
{
test: /\.postcss$/,
loaders: [
"style-loader",
{
loader: "css-loader",
options: { modules: true, importLoaders: 1 }
},
"postcss-loader",
]
}
]
}
})
.version()
.sourceMaps()
tailwind.config.js:
const defaultTheme = require('tailwindcss/defaultTheme')
module.exports = {
purge: [
'./resources/views/**/*.blade.php',
'./resources/css/**/*.css',
],
sourceMap: false,
theme: {
//...
},
plugins: [],
}
postcss.config.js:
module.exports = {
plugins: [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer'),
],
};
package.json:
{
//...
"devDependencies": {
"#babel/preset-env": "^7.9.6",
"#tailwindcss/custom-forms": "^0.2.1",
"axios": "^0.19",
"cross-env": "^7.0",
"css-loader": "^3.5.3",
"laravel-mix": "^5.0.1",
"laravel-mix-tailwind": "^0.1.0",
"lodash": "^4.17.13",
"postcss-css-variables": "^0.17.0",
"postcss-loader": "^3.0.0",
"postcss-nesting": "^7.0.1",
"resolve-url-loader": "^3.1.0",
"sass": "^1.15.2",
"sass-loader": "^8.0.0",
"style-loader": "^1.2.1",
"tailwindcss": "^1.4",
"vue-svgicon": "^3.2.6",
"vue-template-compiler": "^2.6.11"
},
"dependencies": {
"#babel/plugin-syntax-dynamic-import": "^7.8.3",
"#inertiajs/inertia": "^0.1.9",
"#inertiajs/inertia-vue": "^0.1.4",
"alpinejs": "^2.3.5",
"popper.js": "^1.16.1",
"portal-vue": "^2.1.7",
"postcss-import": "^12.0.1",
"postcss-nested": "^4.2.1",
"postcss-nested-ancestors": "^2.0.0",
"vue": "^2.6.11",
"vue-i18n": "^8.17.7",
"vue-meta": "^2.3.3"
}
}
Add this to webpack.config.js :
module: {
rules: [
{
test: /\.(postcss)$/,
use: [
'vue-style-loader',
{ loader: 'css-loader', options: { importLoaders: 1 } },
'postcss-loader'
]
}
],
},
Found here https://github.com/JeffreyWay/laravel-mix/issues/2211#issuecomment-546123921

Type error during importing vue-formio to my vue template

I have a problem with importing vue-formio to my vue component.
Can't import FormBuilder without errors :(
After:
import { FormBuilder } from 'vue-formio';
I see in the console:
TypeError: Object prototype may only be an Object or null: undefined
Whole error You can see here: see print screen
TypeError: Object prototype may only be an Object or null: undefined
Main import:
if (document.body.classList.contains("hr:controller-requisition:action-edit")) {
require.ensure([], () => {
require("./views/requisition/edit.es6.js").default;
});
}
My formio.es6.js file:
import Vue from "vue";
import formio from "./show.vue";
import { store } from "HRComponets/store/store.es6";
export default new Vue({
el: "#formio-show",
data: {},
store,
render(h) {
return h(formio);
}
});
My vue component file:
Hi Guys, need help with vue-formio
<script>
import { FormBuilder } from 'vue-formio';
export default {
name: "formioShow",
data() {
return {
schema: {},
}
},
components: {
FormBuilder
},
};
</script>
My package.json file:
{
"name": "core",
"version": "1.0.0",
"description": "ortal",
"main": "index.js",
"directories": {
"test": "tests"
},
"scripts": {
"start": "npm run dev",
"prod": "webpack --config webpack.prod.js",
"dev": "webpack --watch --progress --config webpack.dev.js",
},
"nyc": {
"include": [
"src/**/*.(js|vue)"
],
"instrument": false,
"sourceMap": false
},
"keywords": [
"HR",
"Syrveys"
],
"browserslist": [
"> 2%",
"last 3 versions",
"not ie <= 8"
],
"devDependencies": {
"#vue/test-utils": "^1.0.0-beta.18",
"axios": "^0.18.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"css-loader": "^0.28.11",
"eslint": "^4.19.1",
"expect": "^23.1.0",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"husky": "^1.0.0-rc.8",
"istanbul-instrumenter-loader": "^3.0.1",
"jsdom": "^11.11.0",
"jsdom-global": "^3.0.2",
"less": "^3.0.4",
"less-loader": "^4.1.0",
"mini-css-extract-plugin": "^0.4.0",
"mocha": "^5.2.0",
"mocha-webpack": "^2.0.0-beta.0",
"node-sass": "^4.9.0",
"nyc": "^11.8.0",
"prettier-eslint": "^8.8.1",
"sass-loader": "^7.0.1",
"style-loader": "^0.21.0",
"ts-loader": "^5.1.0",
"typescript": "^3.0.3",
"vue": "^2.5.16",
"vue-loader": "^15.0.10",
"vue-template-compiler": "^2.5.16",
"watchfile-webpack-plugin": "0.0.4",
"webpack": "^4.8.1",
"webpack-cli": "^2.1.3",
"webpack-dev-server": "^3.1.4",
"webpack-merge": "^4.1.2",
"webpack-notifier": "^1.6.0"
},
"dependencies": {
"amcharts3": "github:amcharts/amcharts3",
"eslint-plugin-vue": "^4.7.1",
"formiojs": "^3.5.1",
"jquery": "^3.3.1",
"lodash": "^4.17.10",
"moment-timezone": "^0.5.17",
"npm": "^6.4.1",
"numeral": "^2.0.6",
"vee-validate": "^2.1.0-beta.8",
"vue-formio": "^3.0.0",
"vue-moment": "^4.0.0-0",
"vue-multiselect": "^2.1.0",
"vue-numerals": "0.0.2",
"vue-pdf": "^3.3.1",
"vue-upload-component": "^2.8.9",
"vue-wysiwyg": "^1.7.2",
"vue2-dropzone": "^3.2.2",
"vuelidate": "^0.7.4",
"vuenut": "^0.2.2",
"vuex": "^3.0.1",
"webpack-node-externals": "^1.7.2"
}
}
My webpack config file:
const webpack = require("webpack");
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const VueLoaderPlugin = require("vue-loader/lib/plugin");
const HTMLWebpackPlugin = require("html-webpack-plugin");
const config = {
entry: {
core: "./src/AppBundle/VueComponents/main.es6.js",
hr: "./src/HRBundle/VueComponents/main.es6.js",
pm: "./src/PerformanceManagementBundle/VueComponents/main.es6.js"
},
output: {
filename: "[name]-app.js",
path: __dirname + "/web/assets/core/js/",
hotUpdateChunkFilename: "../webpack-hot-reload/hot-update.js",
hotUpdateMainFilename: "../webpack-hot-reload/Updatehot-update.json",
publicPath: "/assets/core/js/"
},
watchOptions: {
aggregateTimeout: 300,
poll: 1000,
ignored: /node_modules/
},
module: {
rules: [
{
test: /\.vue$/,
loader: "vue-loader"
},
{
test: /\.ts$/,
exclude: /node_modules|vue\/src/,
loader: "ts-loader",
options: {
appendTsSuffixTo: [/\.vue$/]
}
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
},
{
test: /.scss$/,
use: ["style-loader", "css-loader"]
},
{
test: /\.less$/,
use: ["vue-style-loader", "css-loader", "less-loader"]
},
{
test: /\.es6.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "babel-loader"
}
}
]
},
plugins: [
new VueLoaderPlugin(),
new HTMLWebpackPlugin(),
new webpack.HotModuleReplacementPlugin(),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css"
})
],
externals: {
jquery: "jQuery"
},
resolve: {
alias: {
vue: "vue/dist/vue.js",
HRComponets: path.resolve(__dirname, "./src/HRBundle/VueComponents")
},
extensions: ["*", ".js", ".vue", ".json", ".ts"]
}
};
module.exports = config;

React Native Test with Jest impossible to mock Geolocation

I tried to find a solution on the web and I found this Stackoverflow answer, I followed the instructions but I was blocked:
TypeError: Cannot set property 'geolocation' of undefined
So when I remove the solution my error is:
ReferenceError: navigator is not defined
My package.json looks like this:
"dependencies": {
"eslint-plugin-react-native": "^3.2.0",
"prop-types": "^15.6.0",
"react": "16.0.0",
"react-native": "0.51.0",
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-eslint": "^8.1.2",
"babel-jest": "^22.4.1",
"babel-preset-react-native": "4.0.0",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"eslint": "^4.14.0",
"eslint-plugin-react": "^7.5.1",
"jest": "^22.4.2",
"jest-enzyme": "^6.0.0",
"react-dom": "^16.2.0",
"react-scripts": "^1.1.1",
"react-test-renderer": "16.0.0-beta.5"
},
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"js",
"jsx"
],
"moduleDirectories": [
"node_modules"
],
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-navigation)"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/assetsTransformer.js",
"\\.(css|less)$": "<rootDir>/assetsTransformer.js"
},
"verbose": true
},
"plugins": [
"react",
"react-native"
],
"ecmaFeatures": {
"jsx": true
},
"env": {
"react-native/react-native": true
}
And my test is just:
test('Map Component', () => {
// create the snapshot
const tree = renderer.create(<Map/>).toJSON();
// test the snapshot
expect(tree).toMatchSnapshot();
});
The error is on this line, on the navigator:
navigator.geolocation.getCurrentPosition((position) => {
For the moment I am not testing my component with the navigator. I hope some of you have a solution, please.
Add this in your jest setup.js:
global.navigator = {
geolocation: {
clearWatch: jest.fn(),
getCurrentPosition: jest.fn((success, failure, options) => {
success({
coords: {
longitude: 60,
latitude: 60,
},
});
}),
stopObserving: jest.fn(),
watchPosition: jest.fn(),
},
};
The setup.js file is the one you specify in your package.json file. i.e:
"jest": {
"setupFiles": [
"<rootDir>/__tests__/setup.js"
],
...