chihab / dotenv-run

Seamlessly load environment variables. Supports cli, esbuild, rollup, vite, webpack, angular. ESM and Monorepos.
246 stars 17 forks source link

Conflict with block-scoped @types/node on env.d.ts #16

Closed stephane-tessier closed 1 year ago

stephane-tessier commented 2 years ago

Hi

I'd like to reopen https://github.com/chihab/ngx-env/issues/8

I have the same problem but I didn't understand the fix.

I have src/env.d.ts:

declare let process: {
  env: {
    NG_APP_ENV: string;
    // Replace the line below with your environment variable for better type checking
    NG_APP_apiHost: string;
    NG_APP_apiURL: string;
  };
};

and when I run my linter:

tsc --noEmit && eslint . --ext js,ts --quiet --fix

"Cannot redeclare block-scoped variable 'process'."

image

chihab commented 2 years ago

Thanks for reporting that @stephane-tessier.

Could you please confirm that you don't have any issues with type checking on your editor nor when using CLI commands (ng serve...)?

stephane-tessier commented 2 years ago

Yes, I can confirm that. Everything works fine except the tsc cli

chihab commented 2 years ago

The only way I see to make it work with tsc is to update the tsconfig files generated by the CLI, something like types: [] in tsconfig.json but not sure if that's the best/ a viable solution.

stephane-tessier commented 2 years ago

Not sure what you mean.

In my package.json I have:

    "@types/jasmine": "3.10.2",
    "@types/luxon": "2.0.7",
    "@types/node": "16.11.10",

So in tsconfig.json I tried to force jasmin and luxon:

  "types": ["luxon", "jasmine"],

but it didn't solve the problem.

BUT if I declare the types directly in the cli args, it seems to do the trick :partying_face:

tsc --noEmit --types jasmine,luxon && eslint . --ext js,ts --fix

It will do for now. But if you have a cleaner solution let me know! Thanks.

stephane-tessier commented 2 years ago

the only error I found is when I run ng run my-project:server because there is types: [ 'node'] in the tsconfig.server.json file so it conflicts the exact same way. I solved it by adding "skipLibCheck": true, in the compilerOptions of the tsconfig.server.json file.

Also, I think tsc --noEmit --skipLibCheck && eslint . --ext js,ts --quiet --fix is better than specifying the types