question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable consuming of ES modules in extensions

See original GitHub issue

When developing extensions and using either JavaScript or TypeScript we are unable to consume ES modules, only somewhat legacy CommonJS modules, setting the type to module and rewriting the extension to use import instead of require breaks the extension, generating an exception that states that all modules should use import instead of require in internal VS Code JavaScript files, I conclude it’s caused by the type: module that forces Node to treat all .js files as ES modules. Tried using TypeScript which transpiles its own syntax to CommonJS module - so that’s a no, I have also tried using just .mjs extension, again the same issue.

What is the status of this issue and are there plans to enable using of ES modules in extension development? That (could) bring somewhat big performance gains when bundling extensions with, for example, esbuild because it would enable tree-shaking - dead code removal, thus loading only necessary code. But I think this is not an extension API only issue, right? This needs to be done for VS Code itself?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:126
  • Comments:26 (11 by maintainers)

github_iconTop GitHub Comments

19reactions
andschwacommented, Sep 8, 2021

For what it’s worth, I ran into this trying to update node-fetch from 2.x to 3.x, since the newer version is ESM only. Looks to be the direction things are going, so extension developers are only more likely in the future to run into issues due to lack of ESM support.

16reactions
igorskyflyercommented, Aug 23, 2021

Closing after 15 days of no reply.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to import/consume ES6 modules which are in .js ...
1 Answer 1 · Install @std/esm ( npm i --save @std/esm ) · Add "@std/esm":"cjs" to your package.json · Now node -r @std/esm...
Read more >
How to Use ECMAScript Modules in Node.js
1. Enabling ECMAScript modules in Node.js · The module's file extension is .mjs · Or the module's nearest parent folder has { "type":...
Read more >
ES modules: A cartoon deep-dive - Mozilla Hacks - the Web ...
When you're developing with modules, you build up a graph of dependencies. The connections between different dependencies come from any import ...
Read more >
Using ECMAScript modules (ESM) with Node.js
A brief introduction to using ES modules ... The mjs extension can lead to some confusion when we compare its use against js...
Read more >
Documentation - ECMAScript Modules in Node.js - TypeScript
This code works in CommonJS modules, but will fail in ES modules because relative import paths need to use extensions. As a result,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found