Closed
Description
Bug report
Suppose a project is trying to maintain compatibility with Node 12 and/or 14:
- 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:
webpack-dev-middleware/package-lock.json
Lines 3304 to 3308 in 4194cd0
Metadata
Metadata
Assignees
Labels
No labels