Custom package import could not find index.js

I have such a package with the following structure

clipboard.png

index.js

import apiList from "./interface"

const install = Vue => {
    if (install.installed)
        return;
    install.installed = true
    Object.defineProperties(Vue.prototype, {
        api: {
            get() { return apiList }
        }
    })
}


export default install

when I introduce the package like this, it can run normally

import api from "@/assets/js/http/index"

but that won"t work

import api from "@/assets/js/http"

doesn"t it mean that webpack introduces the package name and automatically looks for the main field of index.js or package.json?
but what"s the problem with introducing the package name "@ / assets/js/http" invalid directly here?

Jun.24,2022

I also encountered this problem. How to solve it? I would like to ask


'@ / assets/js/http' to find the http.js file when it is addressed. You can try'@ / assets/js/http/'.
node will only be used as a folder when it ends with'/'to find the 'index' file inside.
seems to have a third-party library that can omit this'/ 'directly.

Menu