Node.js 如何将绝对模块导入设置为TypeScript?
启用绝对导入路径的“最佳”方式是什么,即Node.js 如何将绝对模块导入设置为TypeScript?,node.js,typescript,Node.js,Typescript,启用绝对导入路径的“最佳”方式是什么,即 import { my_module } from 'src/my_module_file'; 这上面有一张纸;声称这可以通过tsconfig.json的编译器选项中的baseUrl和path设置来实现,有些人则相反。作为一个打字新手,我有点困惑 我是否需要设置,或者TypeScript编译器中是否有在编译期间将绝对路径转换为相对路径的功能 不走运地尝试了这种tsconfig.json: { "compilerOptions": {
import { my_module } from 'src/my_module_file';
这上面有一张纸;声称这可以通过tsconfig.json
的编译器选项中的baseUrl
和path
设置来实现,有些人则相反。作为一个打字新手,我有点困惑
我是否需要设置,或者TypeScript编译器中是否有在编译期间将绝对路径转换为相对路径的功能
不走运地尝试了这种tsconfig.json:
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"lib": ["es2017"],
"removeComments": true,
"sourceMap": true,
"baseUrl": "./",
"paths": {
"*": ["./*"]
},
"rootDir": "server",
"outDir": "generated",
"typeRoots": ["node_modules/@types"]
},
"include": [
"server/**/*.ts"
],
"exclude": [
"node_modules"
]
}
另外,使用Node.js并使用ts Node运行我的应用程序