Per the readme, ESM imports are supported for fs-extra's own methods, like so:
import { outputFile, outputFileSync } from 'fs-extra/esm'
However, fs-extra's types and package configuration causes vscode to import the package like so when completing intellisense:
import { outputFile, outputFileSync } from "fs-extra";
That usually works fine, except the methods that deal with json: outputJson, readJson, writeJson, which result in a Named export not found error:
import { outputJson } from "fs-extra";
node test
file:///G:/root/projects/temp/test.js:1
import { outputJson } from "fs-extra";
^^^^^^^^^^
SyntaxError: Named export 'outputJson' not found. The requested module 'fs-extra' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'fs-extra';
const { outputJson } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)
Node.js v18.13.0
Importing them using fs-extra/esm works...
import { outputJson, readJson, writeJson } from "fs-extra/esm";
But vscode intellisense won't import them that way, and they're missing all types:
Importing them like so works with fs-extra's types:
fs-extra
version: 11.1.1Per the readme, ESM imports are supported for fs-extra's own methods, like so:
However, fs-extra's types and package configuration causes vscode to import the package like so when completing intellisense:
That usually works fine, except the methods that deal with json: outputJson, readJson, writeJson, which result in a Named export not found error:
Importing them using fs-extra/esm works...
But vscode intellisense won't import them that way, and they're missing all types:
Importing them like so works with fs-extra's types:
But intellisense will still auto import them incorrectly if you write one that isn't already imported: