import-fresh
Import a module while bypassing the cache
Last updated 2 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install import-fresh 
SYNC missed versions from official npm registry.

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

Current Tags

  • 4.0.1                                ...           latest (2 months ago)

10 Versions

  • 4.0.1                                ...           2 months ago
  • 4.0.0                                ...           9 months ago
  • 3.3.1                                ...           2 years ago
  • 3.3.0                                ...           6 years ago
  • 3.2.2                                ...           6 years ago
  • 3.2.1                                ...           7 years ago
  • 3.2.0                                ...           7 years ago
  • 3.1.0                                ...           7 years ago
  • 3.0.0                                ...           8 years ago
  • 2.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Total 30
Today 0
This Week 0
This Month 13
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (4)

© 2010 - cnpmjs.org x YWFE | Home | YWFE