小编Gar*_*med的帖子

打字稿不替换 tsconfig 中定义的非相对路径

我试图使用自定义路径来简化常用模块的导入,我设置了这个配置:

// 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)

javascript node.js typescript

7
推荐指数
1
解决办法
3794
查看次数

标签 统计

javascript ×1

node.js ×1

typescript ×1