我是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 { RootState, storeBuilder, CustomerStore } from './../store';
我需要任何额外的配置或包吗?我的堆栈:
- vue 3.0.1
- tsc 3.0.3
'@store';
应该
'@/store';
好的找到解决方案......并且可以通过'@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'),
},
};
}
}