2

My vue-cli version is 4.5.15, but it cannot resolve @ as ./src and all paths using '@' are not found. Why did this happen and how could I solve it?

enter image description here enter image description here enter image description here

2
  • 3
    did you write it with the /component? like import Footer from '@/layout/Footer'? I think you can't import a folder with multiple components, or am I wrong? Commented Feb 12, 2022 at 16:11
  • 1
    I have known what the problem is. It's because I used 'Index.vue' as the name before and git is insensitive to capital. So it cannot find the path. Vue has supported ``` import xxx from "@/xxx" ``` if the name of your file you want to import is "index.vue". Thanks a lot for your answer! Commented Feb 13, 2022 at 8:40

3 Answers 3

4

Your statement tries to import a file which does not exist: import Layout from '@/layout' would work with layout.vue or layout/index.js, neither of which is present.

To fix this, you can either import the single components with their full path (as mentioned in @wittgenstein's comment): import Footer from '@/layout/Footer'

Or you can create layout/index.js which exposes all components inside the directory:

import Footer from './Footer.vue'
import Header from './Header.vue'
// ...

export default {
  Footer, Header, // ...
}

Then you can import components like that: import { Footer, Header } from '@/layout'

Sign up to request clarification or add additional context in comments.

2 Comments

layout.vue won't necessarily work, in some setups .vue extension is required in import
I have known what the problem is. It's because I used 'Index.vue' as the name before and git is insensitive to capital. So it cannot find the path. Vue has supported ``` import xxx from "@/xxx" ``` if the name of your file you want to import is "index.vue". Thanks a lot for your answer!
1

It is not possible to import a folder, you will have to import a single file from the layout folder:

import Footer from "@/Layout/Footer.vue"
import Header from "@/Layout/Header.vue"
import Index from "@/Layout/Index.vue"
import Sidebar from "@/Layout/Sidebar.vue"
import Sidebar2 from "@/Layout/Sidebar2.vue"

If you want to import every file, you will have to this all manually, because you cannot import a folder.

Hope this will work for you!

1 Comment

I have known what the problem is. It's because I used 'Index.vue' as the name before and git is insensitive to capital. So it cannot find the path. Vue has supported ``` import xxx from "@/xxx" ``` if the name of your file you want to import is "index.vue". Thanks a lot for your answer!
1

I have known what the problem is. It's because I used 'Index.vue' as the name before and git is insensitive to capital. So it cannot find the path. Vue has supported

import xxx from "@/xxx"

if the name of your file you want to import is "index.vue". enter image description here Thanks a lot for your answers!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.