-
Notifications
You must be signed in to change notification settings - Fork 30.7k
Description
Bug report
Describe the bug
↑
This file overrides the original implementation of the ProcessEnv typing, which causes negative side effects in third-party libraries that rely on it. In my case this was execa.
To Reproduce
-
Create a Next.js app, ensure
tsconfig.jsonandnext-env.d.tshave been autogenerated. -
Install
execaandts-node.yarn add execa ts-node -
In
test.tswrite something like:import execa from "execa"; execa("printenv", [], { env: { HELLO: "world", NODE_ENV: "development", }, extendEnv: false, stdout: "inherit", });
-
Observe no typing issues and ensure that the command works by running:
yarn ts-node --transpile-only --compiler-options="{\"module\": \"commonjs\"}" test.tsOutput:
HELLO=world NODE_ENV=development ✨ Done in 0.42s. -
Comment out
NODE_ENV: "development",intest.ts, which is a totally valid action. -
Observe the following TypeScript error in the editor:
Argument of type '{ env: { HELLO: string; }; extendEnv: false; stdout: "inherit"; }' is not assignable to parameter of type 'Options<null>'. Types of property 'env' are incompatible. Property 'NODE_ENV' is missing in type '{ HELLO: string; }' but required in type 'ProcessEnv'.ts(2345) global.d.ts(10, 14): 'NODE_ENV' is declared here.
Expected behavior
I would not expect Next.js to pollute Node's ProcessEnv interface, thus not causing typing false-positives in third-party libraries like execa. I'm using execa in a project that includes a few data-processing commands in addition to the Next.js app itself.
System information
- Version of Next.js: 9.0.3
Additional context
git blame points to #7648