按推荐按需引入vant启动服务时依然报找不到vant的两个相关依赖
"dependencies": {
"axios": "^0.19.0",
"core-js": "^2.6.5",
"vant": "^2.0.9",
"vue": "^2.6.10",
"vue-router": "^3.0.3",
"vuex": "^3.0.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.9.0",
"@vue/cli-plugin-eslint": "^3.9.0",
"@vue/cli-service": "^3.9.0",
"@vue/eslint-config-prettier": "^4.0.1",
"babel-eslint": "^10.0.1",
"babel-plugin-import": "^1.12.0",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"sass": "^1.18.0",
"sass-loader": "^7.1.0",
"vue-template-compiler": "^2.6.10"
}
以上可以看到我的全局dependency中已成功安装vant 2.0.9 而开发环境已成功安装babel-plugin-import 1.12.0
module.exports = {
presets: ["@vue/app"],
plugins: [
['import', {
libraryName: 'vant',
libraryDirectory: 'es',
style: true
}, 'vant']
]
};
而对应的babel.config.js文件也添加了vant的plugin如上图
<template>
<div>
<van-button type="primary">Primary</van-button>
</div>
</template>
<script>
import axios from 'axios';
import {Button} from 'vant';
export default {
name: 'contatcList',
components: {
[Button.name] : Button
},
created() {
}
}
</script>
最后也在相应的自定义组件ContactList.vue中import且在components中注册并在template中使用 可起服务的时候依然报找不到vant对应的两个依赖 不知道哪位大神能帮忙解答 感激涕零>_<
These dependencies were not found:
* vant/es/button in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0
-0!./node_modules/vue-loader/lib??vue-loader-options!./src/views/ContactList.vue?vue&type=script&lang=js&
* vant/es/button/style in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??
ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/views/ContactList.vue?vue&type=script&lang=js&
To install them, you can run: npm install --save vant/es/button vant/es/button/style
P.S.: 即使我尝试了跑以上推荐的命令 npm install --save vant/es/button vant/es/button/style 依然还是会报错 所以只好post在这里看大家有没有遇到过类似的问题了>_<