VS Code: Easily convert require statements into modern ES module imports
Last updated: 19th July 2020
Convert your require()
's into ES Module imports by clicking the 💡️ lightbulb icon and selecting 'Convert to ES6 module'. Using this feature can convert your code from this:
const path = require('path');
const crypto = require('crypto');
const fetch = require('node-fetch');
const {name} = require('./animal.js');
Into this:
import path from 'path';
import crypto from 'crypto';
import fetch from 'node-fetch';
import { name } from './animal.js';
As a bonus, this also works with exports
!

I also shared this on twitter!