Skip to content

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

Closed
@octogonz

Description

@octogonz

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/[email protected][email protected]
  /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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions