You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running tsc I'm able to compile all files without erros, but output: dist/server/index.js is
"use strict";
var express = require("express");
var config_1 = require("server/config");
...
Resulting with Cannot find module 'server/config' if I'm trying to use it with node dist/sever/index.js.
Why server/config path is not resolved in any way so it would be possible to use compiled code or how to make it resolve it. Or what am I doing or thinking wrong way?
I was also looking for any example/starter/snippet/docs for typescript 2.0+ for node.js showing typescript configuration in action with no luck. Would be nice to have something like that.
Thanks.
My tsc --version is 2.1.4
Note I don't want to use ../../../../relative paths.
The text was updated successfully, but these errors were encountered:
pie6k
changed the title
How to resolve modules for node.js?
How to resolve absolute modules paths for node.js?
Dec 15, 2016
The compiler does not rewrite module names. module names are "resource identifiers" and the compiler does not touch them, just like your string literals. all what baseUrl and paths do is tell the compiler where to find the .d.ts for this module, but no changes to the output are caused by these options.
you can find related discussion on why this is the case in #12597
Considering this I fail to see the benefit of #5039with respect to supporting absolute paths in a node environment. BaseUrl and paths configuration options do not assist with resolution of absolute path references in a typescript project's translated javascript files because ... these options are provided primarily to support tooling ? I will have to read through the use cases spelled out in 5039 to gain a better understanding of the motivations. I spent a bit of time fiddling around trying to get this to work due to my ignorance or obtuseness, not sure which one at the moment :-)
This leaves the options described here to be able to utilize absolute path references for imports that work in vscode tooling, typescript compilation, and at runtime within a node environment. For example, this will allow the original use case to be achieved:
I need modules to be resolved basing on
baseUrl
so output code is usable for node.jsthis is my
src/server/index.ts
and this is my
src/server/config/index.ts
Running
tsc
I'm able to compile all files without erros, but output:dist/server/index.js
isResulting with
Cannot find module 'server/config'
if I'm trying to use it withnode dist/sever/index.js
.Why
server/config
path is not resolved in any way so it would be possible to use compiled code or how to make it resolve it. Or what am I doing or thinking wrong way?This is my
tsconfig.json
:I was also looking for any example/starter/snippet/docs for typescript 2.0+ for node.js showing typescript configuration in action with no luck. Would be nice to have something like that.
Thanks.
My
tsc --version
is2.1.4
Note I don't want to use
../../../../relative
paths.The text was updated successfully, but these errors were encountered: