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

Cannot find name 'Config' #16

Closed
Cuneytt opened this issue Jun 27, 2018 · 16 comments
Closed

Cannot find name 'Config' #16

Cuneytt opened this issue Jun 27, 2018 · 16 comments
Labels

Comments

@Cuneytt
Copy link

Cuneytt commented Jun 27, 2018

I am new to Typescript and sorry if this is a stupid question.

"npm install" runs successfully and generates the Config.d.ts file in config directory.
tsconfig.json has the config directory as one of the typeRoots:

"typeRoots"                       : [
      "config",
      "node_modules/@types"
 ]

And excludes the node_modules directory:

"exclude"        : [
    "node_modules",
    "**/*Test.ts"
 ]

When "tsc" runs it errors out with:

node_modules/node-config-ts/index.d.ts:4:30 - error TS2304: Cannot find name 'Config'

Thanks

@rburgst
Copy link

rburgst commented Jul 11, 2018

having the same problem

@tusharmath
Copy link
Owner

@Cuneytt Sorry for the late response. Is your project on github somewhere? Also can u confirm the version of the library you are using?

@Cuneytt
Copy link
Author

Cuneytt commented Jul 12, 2018

Thank you for the reply @tusharmath. Solved it for now using process.env directly and plan to get to it later. In the meantime, maybe @rburgst will be able to provide details he is running into.

@tusharmath
Copy link
Owner

tusharmath commented Jul 12, 2018

@Cuneytt I also tried your tsc config and got this error —

yarn run v1.7.0
$ /Users/tushar/Documents/Projects/mobile/node_modules/.bin/tsc
error TS2688: Cannot find type definition file for 'deployment'.


error TS2688: Cannot find type definition file for 'env'.


error TS2688: Cannot find type definition file for 'user'.


error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I was able to solve the problem by removing typeRoots config from tsconfig.json.

@Cuneytt
Copy link
Author

Cuneytt commented Jul 12, 2018

@tusharmath Thanks, Will you please post the entire tsconfig.json you used to cross check with mine

@tusharmath
Copy link
Owner

Does NOT work

{
  "compilerOptions": {
    "declaration": false,
    "module": "commonjs",
    "moduleResolution": "node",
    "newLine": "LF",
    "noImplicitAny": true,
    "noUnusedLocals": true,
    "noUnusedParameters": false,
    "sourceMap": true,
    "strictNullChecks": true,
    "strict": true,
    "target": "es6",
    "typeRoots": ["config", "node_modules/@types"]
  },
  "exclude": ["node_modules"]
}

Working

{
  "compilerOptions": {
    "declaration": false,
    "module": "commonjs",
    "moduleResolution": "node",
    "newLine": "LF",
    "noImplicitAny": true,
    "noUnusedLocals": true,
    "noUnusedParameters": false,
    "sourceMap": true,
    "strictNullChecks": true,
    "strict": true,
    "target": "es6",
    "typeRoots": ["node_modules/@types"]
  },
  "exclude": ["node_modules"]
}

@Cuneytt
Copy link
Author

Cuneytt commented Jul 12, 2018

Thank you very much @tusharmath

@Cuneytt Cuneytt closed this as completed Jul 13, 2018
@bgausden
Copy link

In case anyone hits this issue, it can also be caused by tsconfig.json including a "includes" section. If "includes" is not commented out (the default), it's necessary to add ./config to "includes" or tsc won't find the declaration for the Config interface.

e.g

"exclude": ["node_modules", "**/*.spec.ts", "extra_src"],
"include": ["./src/**/*", "./config/**/*"]

@tusharmath tusharmath pinned this issue Jan 14, 2019
@AdelekeAmoo
Copy link

I try import { AuthenticationService } from '../authentication.service';
after compiling it give this ERROR in src/app/login/login.component.ts(17,19): error TS2304: Cannot find name 'AuthenticationService'.

@larka06
Copy link

larka06 commented Nov 17, 2019

This is my tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",

"typeRoots": [
  "config",
  "node_modules/@types"
],

"lib": [
  "es2018",
  "dom"
]

},

"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
it is different than any of the above ones. Can someone help me understand what is happening here

@tusharmath
Copy link
Owner

tusharmath commented Nov 17, 2019 via email

@larka06
Copy link

larka06 commented Nov 19, 2019

My apologies to all. I had myself under the perception that all here were here for the same reason and bug. cannot find name 'Config'

@bgausden
Copy link

@larka06 assuming tsconfig is in the same folder as node_modules (if not, what's the reason?), are you sure it's necessary to include a typeRoots entry?

I don't know that it's a contributing factor but as typeRoots is generally not needed in a TS project, simplifying your tsconfig by removing typeRoots might help with troubleshooting.

@larka06
Copy link

larka06 commented Nov 22, 2019 via email

@tusharmath
Copy link
Owner

tusharmath commented Nov 22, 2019 via email

@tusharmath
Copy link
Owner

@larka06 I guess you could be having the same issue — #51 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants