Weekly Webtips
Published in

Weekly Webtips

Say “Goodbye” Relative Imports in NodeJS Projects

Photo by Ferenc Almasi on Unsplash
Relative imports! Nightmare! 😅

Code example

Code example
src/util/common/number.js
import { sum, subtract } from 'lib/math';

Main steps

1. Create “jsconfig.json” file in the root path of your project.

jsconfig.json

2. Configure babel

npm install --save-dev @babel/core @babel/cli @babel/preset-env babel-plugin-module-resolver
.babelrc.js
package.json

Result

bash
dist/util/common/number.js
dist/index.js

References:

--

--

Explore the world of web technologies through a series of tutorials

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store