![](/img/trans.png)
[英]Npm link try to find module in src folder instead of dist folder
[英]My Vue NPM imports can only find the modules if they are inside the src folder and not project root
在我的应用程序根目录中,我有 /node_modules/ 和 /src/
我已经运行 npm install 并使用 npm install axios --save 等安装了我的所有依赖项我确实看到它们被添加到 node_modules 目录但我的项目没有以下错误:
Failed to compile.
./src/main.js
Module not found: Error: Can't resolve 'axios' in '/app/src'
如果我在我的 /src/ 目录中手动创建一个 node_modules 文件夹,并放置 axios 和我的其他依赖项,它可以工作.. 但从我读过的内容来看,我不应该以这种方式处理我的节点模块。 看来我需要让我的依赖项指向不同的路径?
奇怪的是我从 'vue' 导入 Vue 和从 './App.vue' 导入 App 工作正常,基本上是之后的所有内容都无法编译。
我的 main.js:
import Vue from 'vue'
import App from './App.vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
import firebase from 'firebase'
import "firebase/auth";
import "firebase/analytics";
import "firebase/firestore";
import moment from 'moment'
Vue.use(VueAxios, axios)
Vue.config.productionTip = false
new Vue({
render: h => h(App),
firebase: firebase,
}).$mount('#app')
我还尝试删除所有节点模块,清除 NPM 缓存并重新安装 NPM 依赖项,但无济于事。
而不是use
function 全局添加您的 axios 实例,您可以尝试像这样添加它:
import Vue from 'vue'
import App from './App.vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
import firebase from 'firebase'
import "firebase/auth";
import "firebase/analytics";
import "firebase/firestore";
import moment from 'moment'
Vue.config.productionTip = false
Vue.prototype.$axios = Axios; //<---- like that
new Vue({
render: h => h(App),
firebase: firebase,
}).$mount('#app')
之后尝试再次编译。 然后,您可以使用this.$axios
在每个组件上调用您的 axios 实例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.