---
title: "How to dynamically import JavaScript modules"
url: https://daily.dev/posts/how-to-dynamically-import-javascript-modules-6x2r4cpn6
source_url: https://flaviocopes.com/javascript-dynamic-import/
type: article
source: "Flavio Copes"
published: 2022-05-14T06:12:36.165Z
updated: 2022-05-14T06:12:36.166Z
tags: ["javascript"]
reading_time: 1
upvotes: 35
comments: 3
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to dynamically import JavaScript modules

**[Flavio Copes](https://daily.dev/sources/flaviocopes)** · 1 min read · 35 upvotes · 3 comments

## Summary

JavaScript Dynamic Imports are a relatively new feature of JavaScript. They let you load modules from a folder without having to know the name of the folder. But doing something like importing test from folder doesn't work. You need to do a dynamic import, in this way:const test = await import ( folder + '/test.js' )

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://flaviocopes.com/javascript-dynamic-import/>

## Community discussion

Top comments from developers on daily.dev.

**@lorezz** · 0 upvotes

> Minimal but solves me a lot of problems. Ty.
> ```js
> const thanks = (await import('ty')).default();

**@jovanmedarovic** · 0 upvotes

> Very practic trick for clean code.

**@fahad07khan** · 0 upvotes

> Good to know new way to import the JS files

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 0 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments
- [CNCF Unveils Schedule for KubeCon \+ CloudNativeCon Europe 2026](https://daily.dev/posts/cncf-unveils-schedule-for-kubecon-cloudnativecon-europe-2026-ikhcoa5cb) · CNCF · 2 upvotes · 0 comments
- [CNCF Debuts KubeCon \+ CloudNativeCon Japan 2026 Schedule](https://daily.dev/posts/cncf-debuts-kubecon-cloudnativecon-japan-2026-schedule-xp5pyudub) · CNCF · 1 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript)

[View this post on daily.dev](https://daily.dev/posts/how-to-dynamically-import-javascript-modules-6x2r4cpn6)
