I have recently made the switch to use Bun as my JS Runtime of choice, and in the switch the relevance of ES Modules vs CommonJS became a moot point because Bun doesn't acknowledge either and it all just works. Unfortunately VSCode doesn't seem to agree and whenever I do something that would work in Bun, but not for Node.JS, it gives me errors such as:
and
I acknowledge that I could simply use @ts-ignore, but that would get out of hand rather quickly. I want to know if there is something I can do to my TSConfig file or my VSCode settings that would rid me of these ESM vs CommonJS errors.
Edit: Changing the package.json to "type": "module"
produces many more errors than it fixes.
Following our exchange in the comments section, you should do the following:
package.json
file to add/modify:"type": "module"
tsconfig.json
file to add/modify:"moduleResolution": "bundler"
"type": "module"
in package.json
tells Typescript to interpret .js
files as ES Modules (instead of CommonJS by default)."moduleResolution": "bundler"
in tsconfig.json
tells Typescript that your bundler is going to take care of the relative import paths and will not require the .js
extension that Node.js needs in ESM mode.