Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"moduleResolution": "node" usage and absolute/relative imports #5304

Closed
rolandjitsu opened this issue Oct 17, 2015 · 8 comments
Closed

"moduleResolution": "node" usage and absolute/relative imports #5304

rolandjitsu opened this issue Oct 17, 2015 · 8 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@rolandjitsu
Copy link

I have recently ran into some issues after having added "moduleResolution": "node" to my tsconfig.json:

{
    "compilerOptions": {
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "module": "system",
        "moduleResolution": "node",
        "noImplicitAny": false,
        "outDir": "dist",
        "rootDir": "./src",
        "sourceMap": true,
        "target": "es5"
    },
    "exclude": [
        "node_modules"
    ]
}

The folder structure of the project looks like:

src/
    app/
        components/
            app/
                app.ts
                app.html
                app.css
        components.ts
        ...
    common/
        animation.ts
        ...

The problem is that when I import { Animation } from 'common/animation'; it tells me that it cannot find the module, so I have to use import { Animation } from '../../../common/animation';. Is it really necessary to have the path as such? And why does it not try to resolve the common/animation relative to rootDir?

@vladima
Copy link
Contributor

vladima commented Oct 17, 2015

node module resolution mimics the way how node looks for modules in runtime (resolution algorithm can be found here). In your case name is not relative - module will always be searched as node module using folder walk and lookup inside node_modules folder. In your case you can specify moduleResolution as classic to use pre-TypeScript 1.6 module resolution logic. Also we have a proposal for path mappings based resolution which I think should do exactly what you need.

Out of curiosity, why do you want to use node module resolution in the first place?

@rolandjitsu
Copy link
Author

I see, makes sense. It is because of Angular 2, it looks like the type definitions work better if I use this option, whereas every time I use the classic resolution I get into trouble with some typings. But it looks like 5039 will solve my issue. Is there a eta on that? Or is it available on the nightly builds?

@vladima
Copy link
Contributor

vladima commented Oct 17, 2015

we plan to start working on this issue quite soon

@rolandjitsu
Copy link
Author

That sounds great. Looking forward 👍

@mhegazy mhegazy closed this as completed Oct 21, 2015
@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Oct 21, 2015
@meriturva
Copy link

Any news here? With angular2 success i think will be really important to resolve modules starting to rootDir with node moduleResolution setting.

@ambition-consulting
Copy link

Same here - we are doing really fancy stuff and need more flexibility regarding import paths. Your suggestion regarding paths similar to systemjs import settings in 5039 would help a lot!

@sanex3339
Copy link

Same problem. Any solution?

@mhegazy
Copy link
Contributor

mhegazy commented Feb 12, 2016

please see the documentation in #5039, and the implementation should be in typescript@next.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

6 participants