Saturday, July 9, 2016

Path Mapping Module Resolution (Typescript 2.0)

Leave a Comment

i have a question about Path Mapping Module Resolution (Typescript 2.0).

I have a project with structure https://github.com/sanex3339/javascript-obfuscator/tree/strictNullChecks

My tsconfig.ts

{   "compilerOptions": {     "target": "ES6",     "module": "commonjs",     "sourceMap": true,     "emitDecoratorMetadata": true,     "experimentalDecorators": true,     "removeComments": true,     "noImplicitAny": true,     "baseUrl": "src/",     "paths": {       "*": [         "*"       ]     }   } } 

In file https://github.com/sanex3339/javascript-obfuscator/blob/dev/src/JavaScriptObfuscator.ts i set

import { INode } from 'interfaces/nodes/INode'; import { IObfuscator } from "interfaces/IObfuscator"; import { IOptions } from 'interfaces/IOptions'; import { IOptionsPreset } from "interfaces/IOptionsPreset";  import { JavaScriptObfuscatorCLI } from 'cli/JavaScriptObfuscatorCLI'; import { Obfuscator } from 'Obfuscator'; import { Options } from 'Options'; 

All interfaces (.d.ts extension) will correctly imported without any errors, but on 3 last imports i get an error:

Can't resolve 'cli/JavaScriptObfuscatorCLI' in '/home/username/PhpstormProjects/javascript-obfuscator/src' 

Why i got this error and why no error during interfaces imports?

Interesting, if i look at trace resolution log, i will see:

======== Resolving module 'cli/JavaScriptObfuscatorCLI' from '/home/username/PhpstormProjects/javascript-obfuscator/src/JavaScriptObfuscator.ts'. ======== Module resolution kind is not specified, using 'NodeJs'. 'baseUrl' option is set to '/home/username/PhpstormProjects/javascript-obfuscator/src', using this value to resolve non-relative module name 'cli/JavaScriptObfuscatorCLI' 'paths' option is specified, looking for a pattern to match module name 'cli/JavaScriptObfuscatorCLI'. Module name 'cli/JavaScriptObfuscatorCLI', matched pattern '*'. Trying substitution '*', candidate module location: 'cli/JavaScriptObfuscatorCLI'. Loading module as file / folder, candidate module location '/home/username/PhpstormProjects/javascript-obfuscator/src/cli/JavaScriptObfuscatorCLI'. File '/home/username/PhpstormProjects/javascript-obfuscator/src/cli/JavaScriptObfuscatorCLI.ts' exist - use it as a name resolution result. Resolving real path for '/home/username/PhpstormProjects/javascript-obfuscator/src/cli/JavaScriptObfuscatorCLI.ts', result '/home/username/PhpstormProjects/javascript-obfuscator/src/cli/JavaScriptObfuscatorCLI.ts' ======== Module name 'cli/JavaScriptObfuscatorCLI' was successfully resolved to '/home/username/PhpstormProjects/javascript-obfuscator/src/cli/JavaScriptObfuscatorCLI.ts'. ======== 

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment