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

Fails to resolve types in non (../)*node_modules/@types pattern directories #20600

Closed
stephenzsy opened this issue Dec 9, 2017 · 2 comments
Closed
Labels
Question An issue which isn't directly actionable in code

Comments

@stephenzsy
Copy link

stephenzsy commented Dec 9, 2017

TypeScript Version: 2.7.0-dev.20171209

Code

With specific typeRoots and baseUrl

tsconfig.json

{
        "target": "ES6",
        "module": "commonjs",
        "lib": ["es5", "es6", "es2015.promise", "dom", "scripthost"],
        "jsx": "react",
        "declaration": true,
        "sourceMap": true,
        "rootDir": "../",
        "stripInternal": true,
        "noEmitOnError": true,
        "skipLibCheck": true,
        "suppressExcessPropertyErrors": true,
        "strict": true,
        "moduleResolution": "node",
        "typeRoots": ["<someDir>/node_modules/@types"],
        "inlineSources": true,
        "experimentalDecorators": true,
        "baseUrl": "<someDir>/node_modules"
}
// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.

import * as nonTypedModule from '<non-typed-npm-module>'

There exists type declaration files in

<someDir>/node_modules/@types/<non-typed-npm-module>/index.d.ts

Expected behavior:

Compile without error

Actual behavior:

error TS7016: Could not find a declaration file for module '<non-typed-npm-module>'
@stephenzsy stephenzsy changed the title Fails to resolving types in non (../)*node_modules/@types Fails to resolve types in non (../)*node_modules/@types Dec 9, 2017
@stephenzsy stephenzsy changed the title Fails to resolve types in non (../)*node_modules/@types Fails to resolve types in non (../)*node_modules/@types pattern directories Dec 9, 2017
@ghost
Copy link

ghost commented Dec 10, 2017

typeRoots affects global definitions. An import statement will go through module resolution to try and find a target.
If you really want to import things from a nested node_modules directory that wouldn't normally be accessible, you could use path mapping (see the "module resolution" link).

@ghost ghost added the Question An issue which isn't directly actionable in code label Dec 10, 2017
@stephenzsy
Copy link
Author

Thanks I added the @types into the paths and it resolves my issue.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
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

1 participant