«   Previous tip Next tip   »

VS Code: Easily convert require statements into modern ES module imports

Last updated: 19th July 2020
Easily convert require statements into modern ES module imports

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!

«   Previous tip Next tip   »

Sign up to receive a developer tip, in the form of a gif, in your inbox each week