Cannot find name 'Config'
Cuneytt opened this issue · 16 comments
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
having the same problem
@Cuneytt Sorry for the late response. Is your project on github somewhere? Also can u confirm the version of the library you are using?
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.
@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.
@tusharmath Thanks, Will you please post the entire tsconfig.json you used to cross check with mine
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"]
}
Thank you very much @tusharmath
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/**/*"]
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'.
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
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'
@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 I guess you could be having the same issue — #51 (comment)