{"id":45136,"library":"import-without-cache","title":"import-without-cache","description":"Import ES modules without cache. Current stable version is 0.4.0, released in 2025. This library intercepts Node.js module loading via hooks to bypass the ESM cache, ensuring fresh imports for every call. It also clears CommonJS cache with clearRequireCache(). Compared to alternatives like clear-module or decache, it supports ES modules natively and handles dependency chains without caching. Requires Node.js ^22.18.0 or >=24.0.0. Not supported on Deno; Yarn PnP requires Node >=24.","status":"active","version":"0.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/sxzz/import-without-cache","tags":["javascript"],"install":[{"cmd":"npm install import-without-cache","lang":"bash","label":"npm"},{"cmd":"yarn add import-without-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add import-without-cache","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"init is a named export, not default.","wrong":"import init from 'import-without-cache'","symbol":"init","correct":"import { init } from 'import-without-cache'"},{"note":"Package is ESM-only; require() is not supported.","wrong":"const clearRequireCache = require('import-without-cache').clearRequireCache","symbol":"clearRequireCache","correct":"import { clearRequireCache } from 'import-without-cache'"},{"note":"Check isSupported at runtime before using init to avoid errors on unsupported platforms.","wrong":null,"symbol":"isSupported","correct":"import { isSupported } from 'import-without-cache'"}],"quickstart":{"code":"import { init, clearRequireCache, isSupported } from 'import-without-cache'\n\nif (!isSupported) {\n  throw new Error('import-without-cache is not supported in this environment.')\n}\n\nconst deregister = init({\n  skipNodeModules: false, // Optional: set true to skip node_modules\n})\n\n// Option 1: use import attributes\nconst mod1 = await import('module-a', { with: { cache: 'no' } })\n\n// Option 2: use no-cache:// protocol\nconst mod2 = await import('no-cache://module-a')\n\nconsole.log('Same instance (should be false):', mod1 === mod2)\n\nclearRequireCache() // Optional: clears CommonJS require cache\n\nderegister() // Clean up hooks when done","lang":"typescript","description":"Demonstrates importing ES modules without cache using both import attributes and no-cache:// protocol, plus clearing CommonJS cache."},"warnings":[{"fix":"Upgrade Node.js to version 22.18.0 or later, or 24.0.0 or later.","message":"Requires Node.js ^22.18.0 or >=24.0.0; will throw on older versions.","severity":"breaking","affected_versions":"<22.18.0"},{"fix":"Use Node.js >=24.0.0 with Yarn PnP, or use a different package manager (npm/pnpm).","message":"Yarn PnP is not supported on Node.js versions earlier than v24.","severity":"gotcha","affected_versions":">=0.0.0 <24.0.0"},{"fix":"Do not use this package with Deno; consider alternative cache-busting methods.","message":"Deno is not supported at all.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Call clearRequireCache() after init to clear CommonJS require cache if needed.","message":"Only ESM modules are supported by default. CommonJS cache must be cleared separately with clearRequireCache().","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"On Bun, skip calling init() and only use clearRequireCache() if needed.","message":"In Bun, init() is unnecessary because ESM imports already behave like CommonJS requires (no caching). clearRequireCache works if you need to clear CJS cache.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use dynamic import() instead of require() for ESM modules, or upgrade to Node.js >=24.13.1.","message":"require(esm) is supported starting in Node.js v24.13.1; earlier versions will throw.","severity":"deprecated","affected_versions":"<24.13.1"}],"env_vars":null,"search_vec":"'0.4.0':14 '2025':17 '22.18.0':66 '24':77 '24.0.0':68 'also':38 'altern':46 'bypass':27 'cach':4,9,30,41,63 'call':36 'chain':61 'clear':39,49 'clear-modul':48 'clearrequirecach':43 'commonj':40 'compar':44 'current':10 'decach':52 'deno':72 'depend':60 'ensur':31 'es':6,55 'esm':29 'everi':35 'fresh':32 'handl':59 'hook':25 'import':2,5,33 'import-without-cach':1 'intercept':20 'javascript':78 'librari':19 'like':47 'load':23 'modul':7,22,50,56 'nativ':57 'node':76 'node.js':21,65 'pnp':74 'releas':15 'requir':64,75 'stabl':11 'support':54,70 'version':12 'via':24 'without':3,8,62 'yarn':73","created_at":"2026-06-07T12:53:32.792564+00:00","updated_at":"2026-06-07T12:53:32.792564+00:00","problems":[{"fix":"Call init() at the start of your application before any no-cache:// import.","cause":"Forgot to call init() before using the no-cache:// protocol.","error":"TypeError: The 'no-cache://' protocol hook is not installed."},{"fix":"Ensure you are running Node.js ^22.18.0 or >=24.0.0, and that the imported module is ESM.","cause":"Used import-without-cache with a non-ESM module or incompatible environment.","error":"ERR_UNSUPPORTED_ESM_URL_SCHEME"},{"fix":"Use named imports matching the module's exports. This is unrelated to cache busting; ensure the module exists.","cause":"Importing a module that has no default export using import without cache.","error":"SyntaxError: The requested module 'module-a' does not provide an export named 'default'"},{"fix":"Check isSupported before using init, and only call if true. Do not use on unsupported platforms.","cause":"Runtime check isSupported returned false (e.g., on Deno or old Node).","error":"Error: import-without-cache is not supported in this environment."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/sxzz/import-without-cache#readme","github":"https://github.com/sxzz/import-without-cache","docs":null,"changelog":null,"pypi":null,"npm":"import-without-cache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}