node-config-ts
node-config-ts copied to clipboard
error TS7016: Could not find a declaration file for module 'node-config-ts'
Describe the bug:
TSError: ⨯ Unable to compile TypeScript:
src/execution-scopes/test-run.ts(9,24): error TS7016: Could not find a declaration file for module 'node-config-ts'. 'C:/app/PaymentAppAutomation/node_modules/node-config-ts/index.js' implicitly has an 'any' type.
Try npm i --save-dev @types/node-config-ts
if it exists or add a new declaration (.d.ts) file containing declare module 'node-config-ts';
src/execution-scopes/test-run.ts(35,57): error TS7006: Parameter 'api' implicitly has an 'any' type.
src/execution-scopes/test-run.ts(38,57): error TS7006: Parameter 'api' implicitly has an 'any' type.
src/execution-scopes/test-run.ts(41,54): error TS7006: Parameter 'api' implicitly has an 'any' type.
src/execution-scopes/test-run.ts(44,57): error TS7006: Parameter 'api' implicitly has an 'any' type.
at createTSError (C:\app\PaymentAppAutomation\node_modules\ts-node\src\index.ts:859:12)
at reportTSError (C:\app\PaymentAppAutomation\node_modules\ts-node\src\index.ts:863:19)
at getOutput (C:\app\PaymentAppAutomation\node_modules\ts-node\src\index.ts:1077:36)
at Object.compile (C:\app\PaymentAppAutomation\node_modules\ts-node\src\index.ts:1433:41)
at Module.m._compile (C:\app\PaymentAppAutomation\node_modules\ts-node\src\index.ts:1617:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1219:10)
at Object.require.extensions.<computed> [as .ts] (C:\app\PaymentAppAutomation\node_modules\ts-node\src\index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1043:32)
at Function.Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1067:19)
at require (node:internal/modules/cjs/helpers:103:18)
at C:\app\PaymentAppAutomation\node_modules\@cucumber\cucumber\src\api\support.ts:28:30
at Array.map (<anonymous>)
at getSupportCodeLibrary (C:\app\PaymentAppAutomation\node_modules\@cucumber\cucumber\src\api\support.ts:28:16)
at runCucumber (C:\app\PaymentAppAutomation\node_modules\@cucumber\cucumber\src\api\run_cucumber.ts:45:36)
run.js:14
Steps To Reproduce:
run npm i node-config-ts
. My version installed is 3.3.1
Create default.json at /config and files under development
run npm i
and see that Config.d.ts created at root of /config
run the application from VSCode via ctrl F5 and error above shown
Expected behavior: No errors occur when application is run and configuration is populated correctly.
Typescript Version: 4.9.3 node-config-ts version: 3.3.1 tsconfig.json
"compilerOptions": {
/* Basic Options */
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./build", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "removeComments": true, /* Do not emit comments to output. */
"noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
"noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedParameters": true, /* Report errors on unused parameters. */
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
"skipDefaultLibCheck": true,
"resolveJsonModule": true,
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"exclude": [
"node_modules"
]
}
package.json
"name": "cucumber-playwright",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"clean": "rimraf target",
"buildOld": "rimraf build && npm run format && npm run lint && tsc && npm run cucumber-check",
"build": "rimraf build && tsc",
"test:execute": "cucumber-js --tags @Regression",
"cucumber-check": "cucumber-js features/**/*.feature --dry-run --require env/set-environment-variables.ts --require world/custom-world.ts --require step-definitions/**/*.ts --require hooks/**/*.ts --require-module ts-node/register --format-options \"{\\\"snippetInterface\\\": \\\"async-await\\\"}\" --format summary --format progress --format progress-bar --publish-quiet",
"debug": "PWDEBUG=1 DEBUG=pw:api cucumber-js",
"only": "cucumber-js -p default -p dev",
"report": "open reports/report.html",
"snippets": "cucumber-js features/**/*.feature --dry-run --format snippets",
"steps-usage": "cucumber-js features/Login/cnoLogin.feature",
"sit": "runScript.bat chromium SIT @SIT_RegressionTest",
"uat": "runScript.bat chromium UAT @UAT_RegressionTest",
"gen-config": "node-config-ts",
"run-scripts": "runScript.bat",
"test:parallel": "cucumber-js --parallel=2",
"postinstall": "node-config-ts"
},
"author": "",
"license": "ISC",
"dependencies": {
"@cucumber/pretty-formatter": "1.0.0",
"@playwright/test": "^1.28.0",
"cucumber-html-reporter": "^5.5.0",
"cucumberjs-parallel": "^2.0.2",
"date-fns": "^2.29.3",
"node-config-ts": "^3.3.1",
"npm-failsafe": "1.0.0",
"playwright": "^1.28.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.3"
},
"devDependencies": {
"@cucumber/cucumber": "^8.9.1",
"@types/fs-extra": "^9.0.13",
"fs-extra": "10.1.0"
}
}
Additional context VSCode 1.75.1 Windows 10
I will say that I have tried to create to do what google says and create a blank module inside a .d.ts file but that didnt work. The only thing that worked was to copy the config.d.ts to an index.d.ts inside the node_module folder.
Also, I'm thinking there is something specific to cucumber that is causing it because the blank module trick worked in a different project I have and cucumber has a config file with module resolution:
cucumber.mjs
const getWorldParams = () => {
const params = {
foo: 'bar',
};
return params;
};
const config = {
requireModule: ['ts-node/register'],
require: ['src/**/*.ts'],
format: [
// 'message:e2e/reports/cucumber-report.ndjson',
'json:test/reports/cucumber-report.json',
'html:test/reports/cucumber-report.html',
'summary',
'progress-bar',
],
formatOptions: { snippetInterface: 'async-await' },
worldParameters: getWorldParams(),
publishQuiet: true,
};
if (process.env.USE_ALLURE) {
config.format.push('./src/support/reporters/allure-reporter.ts');
} else {
config.format.push('@cucumber/pretty-formatter');
}
export default config;
I had to copy Config.ts.d to node_modules/node-config-ts/index.d.ts
I know this is not supposed to be needed anymore, but it was for me today.
Quick workaround is to use:
const { config } = require('node-config-ts');
instead of
import { config } from 'node-config-ts';
The answer from @shayan-hussaini-10p worked for me, although I had to add a lint ignore on my project:
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { config } = require('node-config-ts')
I get the same error:
TSError: ⨯ Unable to compile TypeScript:
src/api/v4.0/oauth2/oauth2.ts:3:24 - error TS7016: Could not find a declaration file for module 'node-config-ts'. '/Users/username/project/node_modules/node-config-ts/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/node-config-ts` if it exists or add a new declaration (.d.ts) file containing `declare module 'node-config-ts';`
I followed all the steps of the installation, but what it wasn't clear is what to do with tsconfig.json
to include this new type, so I tried this:
"include": [
"src/**/*.ts",
"config/**/*.ts"
],
But I don't know if this is the right way of setting up tsconfig.json
Anything more on this? I confirm that everything works as expected for version 2.3.1 but from there on I get this error.
In tsconfig.json if I set strict to false then it runs.
Note, that npx tsc
doesn't report any errors and I only get the error when trying to run my file using
nodemon --watch './**/*.ts' --exec 'ts-node-esm ./lib/server.ts'
For now I am not setting strict to false in tsconfig but rather have modified the post install script to create a symbolic link - I don't know how this will effect build (I am using Vita) but at least I can run using nodemon shown above.
"postinstall": "node-config-ts && cp ./config/Config.d.ts ./node_modules/node-config-ts/index.d.ts"