Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack-dev-middleware/types/index.d.ts requires @types/node@16 when Node.js 12 is still LTS #1194

Closed
octogonz opened this issue Feb 5, 2022 · 1 comment · Fixed by #1195

Comments

@octogonz
Copy link

octogonz commented Feb 5, 2022

Bug report

Suppose a project is trying to maintain compatibility with Node 12 and/or 14:

  1. Try to compile webpack-dev-middleware using TypeScript with @types/node version 12.x

Actual Behavior

Encountered 1 errors:
  [typescript] ../../common/temp/node_modules/.pnpm/webpack-dev-middleware@5.3.1_webpack@5.68.0
  /node_modules/webpack-dev-middleware/types/index.d.ts:204:27 
  - (TS2694) Namespace '"fs"' has no exported member 'StatSyncFn'.

Expected Behavior

Node.js 12 is still LTS, so webpack-dev-middleware should be usable by projects that are trying to maintain support for Node 12 and/or 14.

Suggested solution

The problem is here:

webpack-dev-middleware/types/index.d.ts

type OutputFileSystem = Compiler["outputFileSystem"] & {
  createReadStream?: typeof import("fs").createReadStream;
  statSync?: import("fs").StatSyncFn;  // 👈👈👈
  lstat?: typeof import("fs").lstat;
  readFileSync?: typeof import("fs").readFileSync;
};

The StatSyncFn declaration was newly introduced in @types/node@16:

declare module 'fs' {
    . . .
    export const lstatSync: StatSyncFn;

...whereas in @types/node@14 and before, it looked like this:

declare module 'fs' {
    . . .
    function lstatSync(path: PathLike, options?: StatOptions & { bigint?: false | undefined }): Stats;
    function lstatSync(path: PathLike, options: StatOptions & { bigint: true }): BigIntStats;
    function lstatSync(path: PathLike, options?: StatOptions): Stats | BigIntStats;

So the fix might look like this:

type OutputFileSystem = Compiler["outputFileSystem"] & {
  createReadStream?: typeof import("fs").createReadStream;
  statSync?:  typeof import("fs").lstatSync;  // 👈👈👈
  lstat?: typeof import("fs").lstat;
  readFileSync?: typeof import("fs").readFileSync;
};

Is index.d.ts machine generated?

If so, then maybe webpack-dev-middleware needs to add @types/node@12 to its package.json. The phantom dependency is causing NPM to install the bleeding edge experimental version:

"node_modules/@types/node": {
"version": "17.0.14",
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.14.tgz",
"integrity": "sha512-SbjLmERksKOGzWzPNuW7fJM7fk3YXVTFiZWB/Hs99gwhk+/dnrQRPBQjPW9aO+fi1tAffi9PrwFvsmOKmDTyng==",
"dev": true

@alexander-akait
Copy link
Member

PR welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants