8000 Allow imports with mapped paths to generate resolved path in require() · Issue #32218 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
Allow imports with mapped paths to generate resolved path in require()  #32218
Closed
@ToddThomson

Description

@ToddThomson

I am using an import within a Ts source file:

import { TsCore } from "@TsToolsCommon/Utils/TsCore";

This import gets resolved correctly:

======== Resolving module '@TsToolsCommon/Utils/TsCore' from 'C:/Users/Administrator/Source/Repos/TsTools/Ts2Js/src/TsCompi
56D0
ler.ts'. ========
		Explicitly specified module resolution kind: 'NodeJs'.
		'baseUrl' option is set to 'C:/Users/Administrator/Source/Repos/TsTools/Ts2Js/src', using this value to resolve non-relative module name '@TsToolsCommon/Utils/TsCore'.
		'paths' option is specified, looking for a pattern to match module name '@TsToolsCommon/Utils/TsCore'.
		Module name '@TsToolsCommon/Utils/TsCore', matched pattern '@TsToolsCommon/*'.
		Trying substitution '../../TsToolsCommon/src/*', candidate module location: '../../TsToolsCommon/src/Utils/TsCore'.
		Loading module as file / folder, candidate module location 'C:/Users/Administrator/Source/Repos/TsTools/TsToolsCommon/src/Utils/TsCore', target file type 'TypeScript'.
		File 'C:/Users/Administrator/Source/Repos/TsTools/TsToolsCommon/src/Utils/TsCore.ts' exist - use it as a name resolution result.

In the tsconfig.json, I have:

"baseUrl": ".",
    "paths": {
      "@TsToolsCommon/*": [ "../../TsToolsCommon/src/*" ]
    }

The require() in the compiled js output is:

var TsCore_1 = require("@TsToolsCommon/Utils/TsCore");

I expected that this would be resolved to the full relative path.

This causes grief in mocha test resolution as the "@TsToolsCommon/Utils/TsCore" module cannot be found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0