question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not possible to use full TypeScript syntax in the config file

See original GitHub issue

When I have the following config:

config/app.ts

interface Config {
  clientId: string
  clientSecret: string
}

const config: Config = {
  clientId: process.env.CLIENT_ID,
  clientSecret: process.env.CLIENT_SECRET,
}

export default config;

After tsc transpiling, and running (npm run start:prod) produces:

.../src/config/app.ts:1
(function (exports, require, module, __filename, __dirname) { interface Config {
                                                                        ^^^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:74:7)
    at createScript (vm.js:246:10)
    at Object.runInThisContext (vm.js:298:10)
    at Module._compile (internal/modules/cjs/loader.js:670:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)
    at Module.require (internal/modules/cjs/loader.js:650:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at configPaths.reduce (.../node_modules/nestjs-config/dist/module/config.service.js:211:28)

Which is interesting, as it appears that the code uses require and maybe that causes issues?

https://github.com/nestjs-community/nestjs-config/blob/014f8a29bb7f4b1a92911dfec0cdd667a9844b26/src/module/config.service.ts#L250

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
moltarcommented, Nov 6, 2018

The glob pattern I posted above works. I tested it just now. You can add your other bits to it:

`${process.cwd()}/src/config/**/!(*.d).{js,ts,json}`
1reaction
moltarcommented, Nov 6, 2018

Ok, I narrowed it down to:

src/config/**/!(*.d).{js,ts}

This should exclude the definitions. Can be made tighter, as it also excludes foo.d.js right now, which technically is a valid filename.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSConfig Reference - Docs on every TSConfig option
All relative paths found in the configuration file will be resolved relative ... is provably unreachable due to the use of JavaScript syntax,...
Read more >
How to tell it not to accept TypeScript syntax in JavaScript files?
I have some files that are not TypeScript, but Prettier has no problem formatting them. When I install eslint-config-prettier, ...
Read more >
How to create an application-specific config file for TypeScript?
You can do it the following way. First define structure of your config file, in lets say config.ts: export interface Config { uriPath:...
Read more >
TypeScript Compiling with Visual Studio Code
A tsconfig.json file defines the TypeScript project settings, such as the compiler options and the files that should be included. To do this,...
Read more >
TypeScript configuration - Angular
Browsers can't execute TypeScript directly. Typescript must be "transpiled" into JavaScript using the tsc compiler, which requires some configuration. This page ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found