Socket
Book a DemoInstallSign in
Socket

import-fresh

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

import-fresh

Import a module while bypassing the cache

latest
Source
npmnpm
Version
3.3.1
Version published
Weekly downloads
60M
63.54%
Maintainers
1
Weekly downloads
 
Created
Source

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
  • 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

Keywords

require

FAQs

Package last updated on 02 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts