我试图使用自定义路径来简化常用模块的导入,我设置了这个配置:
// tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": false,
"removeComments": true,
"preserveConstEnums": true,
"outDir": "build",
"allowJs": true,
"target": "es5",
"sourceMap": true,
"baseUrl": ".",
"paths": {
"config": ["app/config"]
}
},
"exclude": [
"node_modules”,
"build"
]
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用“config”导入配置模块,但应用程序无法要求配置文件。编译文件中的 require 路径仍然是“config”。
// result:
var config = require("config");
// what is should be:
var config = require("../../config");
Run Code Online (Sandbox Code Playgroud)
甚至认为模块解析日志显示已解决。
======== Resolving module 'config' from '/abs/path/routes/internal/signin/index.ts'. ========
Module resolution kind is not specified, using 'NodeJs'.
'baseUrl' option is set to '/abs/path', using this value to …Run Code Online (Sandbox Code Playgroud)