我是TS和Vue的新手。
尝试进行vue-cli-service服务时出现以下错误:
This dependency was not found:
* @store in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/ts-loader??ref--12-1!./node_modules/vue-loader/lib??vue-loader-opt
ions!./src/components/HelloWorld.vue?vue&type=script&lang=ts&
To install it, you can run: npm install --save @store
在./src/components/HelloWorld.vue中:
import { RootState, storeBuilder, CustomerStore } from '@store';
在tsconfig.json中:
"baseUrl": "./src",
"paths": {
"@/*": ["src/*"],
"store": ["./store/index.ts"],
但是,当我将import更改为following时,该错误就会消失。
import { RootState, storeBuilder, CustomerStore } from './../store';
我需要任何额外的配置或软件包吗? 我的堆栈:
- vue 3.0.1
- tsc 3.0.3
答案 0 :(得分:1)
'@store';
应该是
'@/store';
答案 1 :(得分:0)
确定解决方案...并可以通过'@ store';
导入需要编辑: vue.config.js 并添加:
const path = require('path');
const ROOT = path.resolve(__dirname);
function root(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [ROOT].concat(args));
}
module.exports = {
configureWebpack: config => {
config.resolve = {
extensions: ['.js', '.ts'],
alias: {
'@store': root('src/store/index.ts'),
},
};
}
}