Relative module was not found in Vue.js when build project - vue.js

I have a project on Vue.js with Typescript and when I run dev server (prod build too) it returns error in console:
ERROR Failed to compile with 1 errors
This relative module was not found:
*./app.vue in ./src/main.ts
I alredy tried to checkout previous project commits, update global and local packages, clone and build project on other machines, delete and reinstall packages, delete package-lock.json, create new project via vue cli and add project files on new configuration - and nothing was changed. Same error. Very strange for me.
Here is my main.ts
import Vue from 'vue';
import App from './app.vue';
import router from './router';
import store from './store';
Vue.config.productionTip = false;
new Vue({
router,
store,
render: (h) => h(App)
}).$mount('#app');
And here App.vue
<template>
<div id="app" class="container-fluid">
<header-component></header-component>
<main id="content" class="content row">
<transition name="fade">
<router-view/>
</transition>
</main>
<footer-component></footer-component>
</div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import HeaderComponent from './components/header/header.component';
import FooterComponent from './components/footer/footer.component';
#Component({
components: {
HeaderComponent,
FooterComponent
}
})
export default class App extends Vue {}
</script>
<style lang="scss">
#import "../node_modules/bootstrap/dist/css/bootstrap.min.css";
#import "../node_modules/font-awesome/css/font-awesome.min.css";
#import "../node_modules/vue2-animate/dist/vue2-animate.min.css";
#import "./styles/main.scss";
</style>
Thanks in advance for help.

It was a spelling error. I changed
import App from './app.vue';
to
import App from './App.vue';
and it fix the error.
Thanx to Derek for help

It could also be, because your node_modules, is not at the root of the project.

If you installed your nuxt project using Yarn try deleting the node_modules and then installing using npm i instead. There are some hooks that will not be run by yarn when installing your dependencies for nuxt.

Related

How to import Storybook component in Turborepo - Vue

I am working on monorepo setup with turborepo combined with Vue & Storybook with below folder structure.
Currently I am unable to import storybook components in my Vue app. How can I do it?
apps/
app1/
app2/
package/
storybook/
hooks/
package.json
package-lock.json
I want to import storybook components from package in my Vue app.
Expected result -
<template>
<div>
<my-custom-button />
</div>
</template>
<script>
import MyCustomComponent from 'storybook';
export default {
components: {
MyCustomComponent
}
}
</script>

Vue3 use component from node_modules

I'm trying to use a component from a node module I installed in Vue3, but it won't work.
I used:
npm install --save vue-slick-carousel
my component
<template>
<div>
<VueSlickCarousel :arrows="true" :dots="true">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</VueSlickCarousel>
</div>
</template>
<script>
import VueSlickCarousel from 'vue-slick-carousel'
import 'vue-slick-carousel/dist/vue-slick-carousel.css'
export default {
name: 'MyComponent',
components: {
VueSlickCarousel
}
}
</script>
It seems like components from the node_modules folder won't work in general, because I have tryed to use an other library. My own components from the src/components folder work perfectly.
I also tryed to register the component globally in my main.js file, but it also won't work.
In my browsers console I always get this error:
Uncaught TypeError: this.$scopedSlots is undefined
Can anyone help?

Vuetify doesn't activate its components

vue#2.6.10
vuetify#2.2.25
I have the following code.
Plugin of Vuetify:
$ cat src/plugins/vuetify.js
import Vue from "vue";
import Vuetify from "vuetify/lib";
Vue.use(Vuetify);
export default new Vuetify({
theme: {
dark: false
}
});
Import and activate it:
$ cat src/main.js
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import vuetify from './plugins/vuetify';
<some irrelevant code and imports reducted>
new Vue({
vuetify,
router,
store,
render: h => h(App)
}).$mount('#app')
Root App HTML code (irrelevant code reducted):
$ cat src/App.vue
<template lang="pug">
#app
component(:is="layout")
router-view /
</template>
And finally I use it in one of pages:
$ cat src/layouts/PrivateLayout.vue
<template lang="pug">
div
v-app
...
router-view
</template>
And this is what I see in the console of DevTools:
Unknown custom element: <v-app> - did you register the component correctly?
Does anybody have an idea what happens? I've read already all the similar question (there are tons) but none of the answers helped.
SOLUTION
Thanks to #morphatic the solution was either:
Import every element manually
or install package that imports everything automaticallty: npm install --save vuetify-loader
Second way, obviously will increase the size as you import redundant things. But it's easier.
This is a sneaky one! Your project structure looks correct to me. The only part that is different from most of the Vuetify apps I've seen is this part:
<template lang="pug">
#app
component(:is="layout")
router-view /
</template>
Even though you appear to have registered all of the Vuetify components globally, when you use dynamic components (<component :is="layout">), my guess is that the build system is doing some sort of lazy loading or late binding which causes <v-app> not to be loaded in time to be recognized. This is mentioned as a special case in the Vuetify docs.
I think there are a couple of things you can try:
Don't load your layout with a dynamic component
Explicitly import VApp to make sure it's there before you need it
I'm sorry I can't be more specific as I haven't solved this particular problem before, but I'm pretty sure that's what's causing it.

What are the Steps to Using Custom Bootstrap SASS in a Vue CLI 3 Project?

I'm trying to change the 'primary', 'danger', 'info', etc theme colors in my project. I use bootstrap-vue. I've tried changing the variables.sass file in the bootstrap folder in node_modules but nothing is reflected. I took a look at the documentation for theming but I can't seem to make sense of it, or get an idea of what I should be doing. Their example looks nothing like the scaffolded project for CLI 4. Should I be creating a custom sass file, installing a sass loader, and importing it?
main.js
import Vue from 'vue';
import App from './App.vue';
import VueRouter from 'vue-router';
import BootstrapVue from 'bootstrap-vue';
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap-vue/dist/bootstrap-vue.css';
import './assets/main.css';
import routes from './routes';
Vue.config.productionTip = false;
Vue.use(VueRouter);
Vue.use(BootstrapVue);
const router = new VueRouter({mode: 'history',routes});
new Vue({
router,
render: h => h(App)
}).$mount('#app')
App.vue
<template>
<div id="app">
<router-view />
</div>
</template>
<script>
export default {
}
</script>
<style lang="css">
#import 'assets/main.css';
#import 'assets/custom_scss.scss';
</style>
If you've created your project with vue-cli 3/4 you can do the following.
Create a custom.scss file and import the bootstrap and bootstrap-vue stylings in there, and customize the variables before the import.
Then import custom.scss in your main.js file along with bootstrap-vue
custom.scss
$theme-colors: (
"primary": black,
"danger": blue
);
#import 'node_modules/bootstrap/scss/bootstrap';
#import 'node_modules/bootstrap-vue/src/index.scss';
main.js
import Vue from "vue";
import BootstrapVue from "bootstrap-vue";
import "../assets/scss/custom.scss";
Vue.use(BootstrapVue);
new Vue({
render: h => h(App)
}).$mount("#app");
Another note is that you should never customize any code inside node_modules as these files should be able to be deleted and re downloaded again without breaking anything.

showing Vue is not defined error while importing vue-router

I have created a new project using vue-cli 'vue init webpack-simple my-app' command. In that fresh installation copy, I'm trying to import vue-router in the App.vue component that was created by default. But it is giving me an error: 'Uncaught ReferenceError: Vue is not defined'. If I import the vue again in App.vue, then the app is working fine. But I already imported the vue in main.js, so why do I need to import it again in App.js? Is there any way I can use the imported vue from main.js? Here is my code:
main.js:
import Vue from 'vue'
import App from './App.vue'
new Vue({
el: '#app',
render: h => h(App)
})
App.vue:
<template>
<div id="app">
<router-view></router-view>
</div>
</template>
<script>
import Vue from 'vue'; //**why I need to import it again? I already imported it in main.js
import VueRouter from 'vue-router';
Vue.use(VueRouter);
import QuestionOne from './components/QuestionOneTemplate';
const routes = [
{ path: '/', name: 'QuestionOne', component: QuestionOne },
];
const router = new VueRouter({
routes
});
window.router = router;
export default {
router,
name: 'app',
data () {
return {
}
}
}
</script>
<style lang="scss">
</style>
Is there any way i can use the imported vue from main.js?
No, you need to import it in every file that uses Vue. The imports/requires are how things get hooked up. Rest assured, each import will be the same singleton instance.
You can get to the router from a Vue component's javascript using this.$router and this.$route without an import, or inside a template, using simply $router and $route
Not recommended, but you can assign Vue to a global in main.js, and use the global without importing.
main.js
import Vue from 'vue';
global.MyVue = Vue
App.vue
import VueRouter from 'vue-router';
MyVue.use(VueRouter);
Why
This is how ES6 links things up. Consider it wiring. If there were more than 1 Vue lib available, how would the linker know which to use? What if another library defined a variable or function called Vue? Perhaps a lib uses its own internal Vue for an event bus or other feature.
Other Thoughts
The explicit import also makes IDE autocompletion and syntax highlighting work better. Some IDEs can add the imports automatically, and that makes life easier.
did you try this ?
import Vue from 'vue'
import VueRouter from 'vue-router'
then use
Vue.use(VueRouter)
because the error message means you need to import vue first to use vue-router
You did the right thing and you don't have to worry about importing Vue in multiple files. When you are shipping your application and build it for production, you will have only one "Vue import". If you take a look at dist folder and your bundled .js files you will notice that Vue is imported only once.