When I have an import fs from 'fs/promises'; or similar in my code base, this gets transpiled to import fs from "../../../promises";, causing an error such as this:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/cdauth/Documents/workspace/programming/web/osm/facilmap/promises' imported from /home/cdauth/Documents/workspace/programming/web/osm/facilmap/server/node_modules/.bin/esrun-1696190329627.tmp.mjs
code = code
.replace(
/(?:^|;)import (.*?) from "..\//gm,
'import $1 from "../../../',
)
.replace(/(?:^|;)import (.*?) from ".\//gm, 'import $1 from "../../');
Here, the ..\/ part in the regular expression matches the fs/. I believe to fix the issue, the ..\/ in the regular expression should become \.\.\/ and the .\/ in the other regular expression should become \.\/.
As a workaround, I can import from node:fs/promises.
When I have an
import fs from 'fs/promises';
or similar in my code base, this gets transpiled toimport fs from "../../../promises";
, causing an error such as this:The problems seems to be in this line:
Here, the
..\/
part in the regular expression matches thefs/
. I believe to fix the issue, the..\/
in the regular expression should become\.\.\/
and the.\/
in the other regular expression should become\.\/
.As a workaround, I can import from
node:fs/promises
.