I'm new to all these and now learning Vue.
I have install Vuex, use export default, and import it but still getting this error =>
WARNING Compiled with 1 warnings
warning in ./src/store/index.js
"export 'createStore' was not found in 'vuex'
The index.js store file
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
import coachesModule from './modules/coaches/index.js';
const store = new Vuex.Store({
modules: {
coaches: coachesModule
}
});
export default store;
The package.json file
{
"name": "vue-first-app",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.5",
"vue": "^3.0.0",
"vue-router": "^4.0.0-rc.5",
"vuex": "^3.5.1"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"#vue/compiler-sfc": "^3.0.0-0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^7.0.0-0"
}
}
After uninstalling Vue using
npm uninstall -g #vue/cli
and reinstall Vue Using
npm install -g #vue/cli#latest
npm i vue vue-router -S
npm install
now still im getting :
INFO Starting development server...
98% after emitting CopyPlugin
WARNING Compiled with 1 warnings 3:56:20 PM
warning in ./src/store/index.js
"export 'default' (imported as 'Vue') was not found in 'vue'
Anyone can help me?
Upd.
You use vue3 and vuex3, but you should use vuex4.
Can you try to use
const store = new Vuex.Store({
// options
})
instead of
const store = createStore({
// options
})
?
According to this docs https://vuex.vuejs.org/guide/#the-simplest-store .
createStore is Vuex 4 syntax, since you're using vuex 3 you should do :
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex)
import coachesModule from './modules/coaches/index.js';
const store = new Vuex.Store({
modules: {
coaches: coachesModule
}
});
export default store;
I had the same problem using Quasar as a UI framework and got it solved by running
yarn add vuex#next
or if you are using npm
npm install --save vuex#next
then rebuilding the project got everything running again.
more details in this ref: https://www.codegrepper.com/code-examples/whatever/%22export+%27createStore%27+was+not+found+in+%27vuex%27
what this did in the background was changing the "vuex":"^3.6.2" to "vuex": "^4.0.2"
Related
I created a new repo with $ npm install vue-app and created some test components.
When i run the command $ npm run dev the application starts in localhost port 3000.
I try to add my component in a WP website. When i build the files and add to my theme, i receive the message:
Uncaught SyntaxError: Cannot use import statement outside a module
I found some documentation for webpack but not for vite.config.js.
Anyone can help?
vite.config.js
// vite.config.js
import vue from '#vitejs/plugin-vue'
export default {
plugins: [vue()]
}
package.json
{
"name": "vite-app",
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
"dependencies": {
"vue": "^3.0.5"
},
"devDependencies": {
"#vitejs/plugin-vue": "^1.2.3",
"#vue/compiler-sfc": "^3.0.5",
"vite": "^2.3.5"
}
}
This is a Vue 2 JavaScript application:
VIcon causing jest test to fail and present this error:
console.error node_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]: Error in render: "TypeError: Cannot read property 'component' of undefined"
found in
---> <VIcon>
<VCheckbox>
<Anonymous>
<Root>
I created this app with the Vue cli tool and used vue add to add the plugin for Vuetify. I'm also using PUG for vue template template, and SCSS instead of css (Node-sass). This might be due to the jest setup which will be provided below. I followed an online setup for ignoring some files and collecting coverage.
module.exports = {
preset: '#vue/cli-plugin-unit-jest',
setupFiles: ['./tests/setup.js'],
moduleNameMapper: {
'^#/(.*)$': '<rootDir>/src/$1',
},
testMatch: [
'**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)',
'**/tests/int/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)',
],
transform: {
".+\\.(css|styl|less|sass|scss|png|jpg|jpeg|mp3|ttf|woff|woff2)$": "jest-transform-stub",
"^.+\\.jsx?$": "babel-jest",
"^.+\\.js?$": "babel-jest"
},
snapshotSerializers: ['jest-serializer-vue'],
collectCoverage: true,
collectCoverageFrom: [
'src/**/*.{js,vue}',
'!src/main.js',
'!src/App.vue',
'!src/plugins/*',
'!src/router/*',
// testing this later
'!src/store/*',
'!src/store/modules/*',
],
};
The jest inner setup file just adds vuetify:
import Vue from 'vue';
import Vuetify from 'vuetify';
Vue.use(Vuetify);
Here is the package.json to see what versions I'm using:
{
"name": "client2",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit --coverage --watchAll",
"test-ci": "vue-cli-service lint && vue-cli-service test:unit && vue-cli-service --mode development --headless",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.21.1",
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vue-notification": "^1.3.20",
"vue-router": "^3.2.0",
"vuetify": "^2.2.11",
"vuex": "^3.4.0"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-plugin-router": "~4.5.0",
"#vue/cli-plugin-unit-jest": "~4.5.0",
"#vue/cli-plugin-vuex": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"#vue/eslint-config-prettier": "^6.0.0",
"#vue/test-utils": "^1.0.3",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-vue": "^6.2.2",
"node-sass": "^4.12.0",
"prettier": "^1.19.1",
"sass": "^1.19.0",
"sass-loader": "^8.0.2",
"vue-cli-plugin-pug": "~2.0.0",
"vue-cli-plugin-vuetify": "~2.0.9",
"vue-template-compiler": "^2.6.11",
"vuetify-loader": "^1.3.0"
}
}
and the test:
import TriBox from '../../src/components/UIContainers/TriBox.vue';
import { createLocalVue, mount } from '#vue/test-utils';
import Vuetify from 'vuetify';
describe('<TriBox /> Unit Tests', () => {
let wrapper;
const localVue = createLocalVue();
localVue.use(Vuetify);
beforeEach(() => {
wrapper = mount(TriBox, {
localVue,
});
});
it(`renders to screen`, () => {
expect(wrapper.exists).toBeTruthy();
});
});
and the component:
<template lang="pug">
.box-container
.left
v-checkbox
.middle
p hello
.right
v-icon mdi-trash-can
</template>
<script>
export default {};
</script>
<style lang="scss" scoped>
</style>
I can't find a specific document pertaining to this being a known bug with Vuetify and Vue2. Anyone have a clue as to how to solve this? I'm thinking it has to do with the jest setup file or how I'm setting the test up and adding vuetify to the local vue. But any suggestions would be helpful.
Based on Vuetify's Jest setup docs:
Don't use localVue.use(Vuetify) because you've already called Vue.use(Vuetify) in the Jest setup file.
Along with localVue, pass vuetify as a new instance of Vuetify to mount():
const localVue = createLocalVue()
let wrapper
beforeEach(() => {
wrapper = mount(TriBox, {
localVue,
vuetify: new Vuetify(),
})
})
Hello guys please am having issues installing plugins on Vue js, so I tried installing Element Ui plugins on my project the installation was successful but in my Vs Code terminal it's bringing out this:
Compiled with 1 warning
warning in ./src/plugins/element.js
"export 'default' (imported as 'Vue') was not found in 'vue'
And I can't access my project on the localhost server it's just blank.
My Main.JS File
import App from "./App.vue";
import router from "./router";
import store from "./store";
import "./plugins/element.js";
createApp(App)
.use(store)
.use(router)
.mount("#app");
Package.Json
"name": "jargonapp",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.5",
"element-ui": "^2.4.5",
"vue": "^3.0.0",
"vue-router": "^4.0.0-0",
"vuex": "^4.0.0-0"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-plugin-router": "~4.5.0",
"#vue/cli-plugin-vuex": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"#vue/compiler-sfc": "^3.0.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^7.0.0-0",
"vue-cli-plugin-element": "~1.0.1"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
It seems that you're using element ui 2 with vue 3 which are not compatible, to work with Vue 3 you have to install the element ui plus
uninstall the current version :
npm uninstall element-ui -S
then install the latest one :
npm i element-plus -S
the main.js minimum content :
import { createApp } from "vue";
import router from "./router";
import store from "./store";
import ElementPlus from "element-plus";
import "element-plus/lib/theme-chalk/index.css";
import App from "./App.vue";
createApp(App)
.use(ElementPlus)
.use(store)
.use(router)
.mount("#app");
I am building a small project with Vue, typescript, vuetify and icons from fontawesome5. But I am coming across a weird challenge that I cant overcome. In dev mode, all the icons are showing fine from font awesome, but when I build for production, the icons show as square boxes. So far, all my components, custom vuetify theme, backend api, everything works as expected in my build, but not the icons. I also noticed that during prod builds, the fontawesome fonts are not are being included which explains the problem. I did try setting a direct link to fontawesome cdn in index.html but that does work either.
My setup is simple. Project intialized with
vue create .
vue add vuetify
So far, this is what I have tried/made sure of are:
import '#fortawesome/fontawesome-free/css/all.css';
import vuetify from './plugins/vuetify';
So css is being imported. I have tried moving around this imoort statement, but that doesnt solve it.
Vuetify init
import Vue from 'vue';
import Vuetify from 'vuetify/lib';
Vue.use(Vuetify);
export default new Vuetify({
theme: {
themes: {
light: {
primary: '#3577F6',
secondary: '#424242',
accent: '#82B1FF',
error: '#FF5252',
info: '#5543BD',
success: '#00695c',
warning: '#F6BC41'
},
dark: {
primary: '#3577F6',
secondary: '#424242',
accent: '#82B1FF',
error: '#FF5252',
info: '#5543BD',
success: '#00695c',
warning: '#F6BC41'
}
},
},
icons: {
iconfont: 'fa',
},
});
I tried moving the css import here, but thats a no go.
My package.json is
{
"name": "client",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build && npm run docs",
"dev": "vue-cli-service serve",
"docs": "./node_modules/.bin/redoc-cli bundle ./docs/swagger.yml --output ./dist/docs.html --options.hideDownloadButton"
},
"dependencies": {
"#fortawesome/fontawesome-free": "^5.13.1",
"axios": "^0.19.2",
"lodash": "^4.17.15",
"roboto-fontface": "*",
"store2": "^2.11.2",
"typeface-open-sans": "0.0.75",
"vue": "^2.6.11",
"vue-class-component": "^7.2.3",
"vue-clipboard2": "^0.3.1",
"vue-matomo": "^3.13.5-0",
"vue-notification": "^1.3.20",
"vue-router": "^3.3.4",
"vuetify": "^2.3.1",
"vuex": "^3.1.3"
},
"devDependencies": {
"#types/lodash": "^4.14.155",
"#vue/cli-plugin-router": "^4.4.4",
"#vue/cli-plugin-typescript": "^4.4.4",
"#vue/cli-plugin-vuex": "^4.4.4",
"#vue/cli-service": "^4.4.4",
"redoc-cli": "^0.9.8",
"sass": "^1.26.8",
"sass-loader": "^8.0.0",
"typescript": "^3.9.5",
"vue-cli-plugin-vuetify": "~2.0.6",
"vue-template-compiler": "^2.6.11",
"vuetify-loader": "^1.5.0"
}
}
Some mention that css-loader is required along with webpack, so I did install css loader but that didnt solve it.
Because I am using the standard vue cli (version #vue/cli 4.4.1), i didnt see a webpack config file.
Dev mode:
Prod serving built files:
How can i fix this?
The issue is likely...
that the $fa-font-path is not defined, and the fonts can't be found.
Solution
Create (and reference in your project) an scss file (like styles.scss) with the following
$fa-font-path: '~#fortawesome/fontawesome-free/webfonts';
#import '~#fortawesome/fontawesome-pro/css/all.css';
this should have it included by webpack
or if you want a specific font pack...
$fa-font-path: '~#fortawesome/fontawesome-free/webfonts';
#import '~#fortawesome/fontawesome-free/scss/fontawesome';
#import '~#fortawesome/fontawesome-free/scss/regular';
#import '~#fortawesome/fontawesome-free/scss/solid';
or you can use the <style> block
<style lang="scss">
$fa-font-path: '~#fortawesome/fontawesome-free/webfonts';
#import '~#fortawesome/fontawesome-pro/css/all.css';
</style>
I tried to run a react-native simulator.
However, this error came out in the simulator:
Failed to load bundle(http://localhost:8081/index.bundle?
platform=ios&dev=true&minify=false)
with error:(/Users/sugawarasyuta/Desktop/albums/index.js:
Cannot read property 'bindings' of null(null))
I double‐checked my code syntax. But I feel like this is not about that. Do you know how to solve this error?
Here are my files:
index.js
import React from 'react';
import { AppRegistry,View } from 'react-native';
import Header from './src/components/header';
import AlbumList from './src/components/AlbumList';
//Create a component
const App = () => (
<View>
<Header headerText= {'albums'} />
<AlbumList />
</View>
);
AppRegistry.registerComponent('albums', () => App );
AlbumList.js
import React,{Component}from 'react';
import {View, Text} from 'react-native';
import axios from 'axios';
class AlbumList extends Component {
componentWillMount(){
axios.get('https://rallycoding.herokuapp.com/api/music_albums')
.then(response => console.log(response));
}
render(){
return(
<View>
<Text>AlbumList!!!</Text>
</View>
);
}
}
export default AlbumList;
These are terminal statements:
/usr/bin/codesign --force --sign - --entitlements /Users/sugawarasyuta/Desktop/albums/ios/build/Build/Intermediates.noindex/albums.build/Debug-iphonesimulator/albums.build/albums.app.xcent --timestamp=none /Users/sugawarasyuta/Desktop/albums/ios/build/Build/Products/Debug-iphonesimulator/albums.app
/Users/sugawarasyuta/Desktop/albums/ios/build/Build/Products/Debug-iphonesimulator/albums.app: resource fork, Finder information, or similar detritus not allowed
Command /usr/bin/codesign failed with exit code 1
** BUILD FAILED **
The following build commands failed:
CodeSign build/Build/Products/Debug-iphonesimulator/albums.app
(1 failure)
Installing build/Build/Products/Debug-iphonesimulator/albums.app
Launching org.reactjs.native.example.albums
org.reactjs.native.example.albums: 8385
This is my package.json. Are those dependencies correct?
{
"name": "albums",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"axios": "^0.18.0",
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
"react": "16.3.1",
"react-native": "^0.56.0"
},
"devDependencies": {
"#babel/preset-env": "^7.0.0-beta.53",
"babel-jest": "23.0.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react-native": "4.0.0",
"eslint-config-rallycoding": "^3.2.0",
"jest": "23.1.0",
"react-test-renderer": "16.3.1"
},
"jest": {
"preset": "react-native"
}
}
I upgraded "babel-preset-react-native" from "4.0.0" to "^5.0.1" and another error came out:
error: bundling failed: SyntaxError:
/Users/sugawarasyuta/Desktop/albums/index.js: Unexpected token (11:3)
10 | const App = () => {
> 11 | <Header headerText= {'albums'} />
| ^
12 |
13 | };
at Parser.raise
(/Users/sugawarasyuta/Desktop/albums/node_modules
/#babel/core/node_modules/babylon/lib/index.js:776:15)
at Parser.unexpected
(/Users/sugawarasyuta/Desktop/albums/node_modules/
#babel/core/node_modules/babylon/lib/index.js:2079:16)
at Parser.parseExprAtom (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:3157:20)
at Parser.parseExprSubscripts (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:2757:21)
at Parser.parseMaybeUnary (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:2736:21)
at Parser.parseExprOps (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:2643:21)
at Parser.parseMaybeConditional (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:2615:21)
at Parser.parseMaybeAssign (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:2562:21)
at Parser.parseExpression (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:2515:21)
at Parser.parseStatementContent (/Users/sugawarasyuta/Desktop/albums/node_modules/#babel/core/node_modules/babylon/lib/index.js:4076:21)
BUNDLE [ios, dev] ../../index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.
I feel like this is not because of syntax error simply, but cause of dependencies. Do you know how can I fix it?
Without any further information, I suspect you need to update babel-preset-react-native.
When upgrading to 0.56, make sure to bump your
babel-preset-react-native package.json dependency to ^5.0.1 or newer.
https://github.com/facebook/react-native/releases
For React Native 0.57
When upgrading to React Native 0.57, follow these steps to fix this issue:
Upgrade the version of React in the package.json to 16.5
Change the babel-preset dependency from "babel-preset-react-native": "^5" to "metro-react-native-babel-preset": "^0.45.0"
Change the .babelrc configuration to:
{
"presets": ["module:metro-react-native-babel-preset"]
}
Run rm -rf node_modules/ to remove your old modules
Run npm install to get a fresh node_modules/
Run react-native upgrade to upgrade your config files
Run rm -rf android/build/ ios/build/ to get rid of your old compiled apps
Run your app again, it should work!
Source for the first steps
REACT NATIVE 0.57 FRESH INSTALLS iOS ANDROID
I did a fresh install of react native from react-native init projectName
The package.json
{
"name": "JesteeTestee",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "^16.5.2",
"react-native": "0.57.4"
},
devDependencies": {
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "^0.47.0",
"react-test-renderer": "16.6.0-alpha.8af6728"
},
"jest": {
"preset": "react-native",
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
}
}
}
As you can see it is the latest, current version of RN#0.57.4 and metro-react-native-babel-preset#0.47.0.
Also the default .babelrc
{
"presets": ["module:metro-react-native-babel-preset"]
}
Simply added the following to the Jest part of the package.json;
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
}
Given the hours I spent finding this today, if you are doing a fresh install and hit a snag just delete the project, start again and try this simple step only.
Tested for react-native run-ios and run-android.
FOR REACT-NATIVE VERSION 0.57 OR MORE
On babel.config.js, simply change presets as below
"presets": ["module:metro-react-native-babel-preset"]
This worked for me after trying many different solutions