launchcodedev / app-config

Easy Configuration Loader with Strict Validation
https://app-config.dev
Mozilla Public License 2.0
69 stars 11 forks source link

Minimal Node/TypeScript example fails with missing `json-schema` dependency #90

Closed jayden-chan closed 3 years ago

jayden-chan commented 3 years ago

Attempting to build a minimal TypeScript NodeJS project fails with this error:

node_modules/@apidevtools/json-schema-ref-parser/lib/index.d.ts:1:76 - error TS2307: Cannot find module 'json-schema' or its corresponding type declarations.

1 import { JSONSchema4, JSONSchema4Type, JSONSchema6, JSONSchema6Type } from "json-schema";
                                                                             ~~~~~~~~~~~~~
Found 1 error.

yarn app-config vars and yarn app-config generate both work fine.

.app-config.schema.yml

type: object
additionalProperties: false

required:
  - testing

properties:
  testing: { $ref: '#/definitions/Testing' }

definitions:
  Testing:
    type: object
    additionalProperties: false
    required: [host, port]
    properties:
      host: { type: string }
      port: { type: integer }

.app-config.meta.yml

generate:
  - { file: 'src/@types/lcdev__app-config/index.d.ts' }

.app-config.yml

testing:
  host: testHost
  port: 12345

src/index.ts

import { config, loadConfig } from "@lcdev/app-config";

async function main() {
  await loadConfig();

  // anywhere in your app, after loadConfig is complete and resolved
  console.log(config); // this is a JSON object, loaded from the YAML file
}

main();

package.json

...
"devDependencies": {
  "@types/node": "^14.14.21",
  "typescript": "^4.1.3"
},
"dependencies": {
  "@lcdev/app-config": "2"
}
...

Additional info:

command output
node -v v14.15.4
yarn app-config -v 2.0.1
yarn tsc -v Version 4.1.3