import-fresh (3.3.1)
Published 2026-02-24 13:58:06 +00:00 by atheaadmin
Installation
registry=npm install import-fresh@3.3.1"import-fresh": "3.3.1"About this package
import-fresh
Import a module while bypassing the cache
Useful for testing purposes when you need to freshly import a module.
ESM
For ESM, you can use this snippet:
const importFresh = moduleName => import(`${moduleName}?${Date.now()}`);
const {default: foo} = await importFresh('foo');
This snippet causes a memory leak, so only use it for short-lived tests.
Install
npm install import-fresh
Usage
// foo.js
let i = 0;
module.exports = () => ++i;
const importFresh = require('import-fresh');
require('./foo')();
//=> 1
require('./foo')();
//=> 2
importFresh('./foo')();
//=> 1
importFresh('./foo')();
//=> 1
Related
- clear-module - Clear a module from the import cache
- import-from - Import a module from a given path
- import-cwd - Import a module from the current working directory
- import-lazy - Import modules lazily
Dependencies
Dependencies
| ID | Version |
|---|---|
| parent-module | ^1.0.0 |
| resolve-from | ^4.0.0 |
Development Dependencies
| ID | Version |
|---|---|
| ava | ^1.0.1 |
| heapdump | ^0.3.12 |
| tsd | ^0.7.3 |
| xo | ^0.23.0 |
Keywords
require
cache
uncache
uncached
module
fresh
bypass