这是我的进口
import { test } from "test";
这些设置将正确导入,但缺少现代TS功能
//tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"test": ["../test"]
}
},
}
这些设置根本不会导入
//tsconfig.json
{
"target": "ESNext", // added a target
"compilerOptions": {
"baseUrl": ".",
"paths": {
"test": ["../test"]
}
},
}
如果我进行测试,看来路径对于ES5来说可以正常工作,而ES6及其以后的路径则不起作用,也不会给出任何有意义的错误。
这是怎么回事?为什么路径在较新的目标中不一样?发生了什么变化,我应该怎么做?
答案 0 :(得分:0)
"moduleResolution": "node"
才能在ES6及更高版本中使用路径
//tsconfig.json
{
"target": "ESNext", // added a target
"compilerOptions": {
"baseUrl": ".",
"moduleResolution": "node"
"paths": {
"test": ["../test"]
}
},
}
如果不包括目标,则默认为ES5。