dividab / tsconfig-paths-webpack-plugin

Load modules according to tsconfig paths in webpack.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: filesystem.readJson is not a function

JakeSidSmith opened this issue · comments

Could you/I update this library to use standard fs methods?

I'm trying to use memfs and unionfs with webpack and getting this error, because readJson is actually not a standard method, it's from: https://github.com/jprichardson/node-fs-extra

Even using the following causes this error:

import * as fs from 'fs';

compiler.inputFileSystem = fs;

I'm happy to open a PR to change to a standard readFile and JSON.parse if you'll accept it?

Related: #24

I'm not sure I follow, this package does not have node-fs-extra as a dependency? Neither does tsconfig-paths which this package depends on. Could you point out where you think this is used?

I am trying to use an in memory file system with webpack, as documented here: https://webpack.js.org/api/node/#custom-file-systems

The issue I'm having is caused by this line:

filesystem.readJson(path2, (err, json) => {

The ResolverFileSystem that is presumably passed around by webpack (typed here) contains standard fs methods, but also a readJson (and readJsonSync):

export interface ResolverFileSystem {

I'm not sure if webpack's documentation is out of date and perhaps they wrap the fs with these additional methods normally, but I can't say for sure.

They seem to have a custom wrapper here: https://github.com/webpack/webpack/blob/95120bdf98a01649740b104bebc426b0123651ce/lib/util/fs.js#L222

But this also accounts for if readJson does not exist. Perhaps this lib should do the same?

Aha, that makes more sense. I guess we could do the same as they do in webpack then and fall back if there is no readJson function. In that case the typings should probably be amended too so ResolverFileSystem.readJson is optional. A PR for this would be welcome, preferably with tests :-).