{"id":25340,"library":"esbuild-plugin-filelastmodified","title":"esbuild-plugin-filelastmodified","description":"An esbuild plugin that exports the last modified timestamp of specific files during the build process. Version 2.0.4 is the latest stable release, with no known breaking changes since v2.0.0. It returns a Unix timestamp (milliseconds) for requested files, integrated as a virtual module. Differentiator: simple, focused utility for cache busting or build-time file info without manual file system reads.","status":"active","version":"2.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/g45t345rt/esbuild-plugin-filelastmodified","tags":["javascript","typescript"],"install":[{"cmd":"npm install esbuild-plugin-filelastmodified","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-filelastmodified","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-filelastmodified","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for plugin to work","package":"esbuild","optional":false}],"imports":[{"note":"CommonJS require works as it also exports a default; prefer named import for clarity.","wrong":"const fileLastModifiedPlugin = require('esbuild-plugin-filelastmodified')","symbol":"fileLastModifiedPlugin","correct":"import { fileLastModifiedPlugin } from 'esbuild-plugin-filelastmodified'"},{"note":"No default export, destructure directly.","wrong":"const fileLastModifiedPlugin = require('esbuild-plugin-filelastmodified').default","symbol":"fileLastModifiedPlugin","correct":"const { fileLastModifiedPlugin } = require('esbuild-plugin-filelastmodified')"},{"note":"Default import also works since both named and default exports point to the same function.","wrong":"import { fileLastModifiedPlugin } from 'esbuild-plugin-filelastmodified'","symbol":"fileLastModifiedPlugin","correct":"import fileLastModifiedPlugin from 'esbuild-plugin-filelastmodified'"},{"note":"Type-only import for TypeScript users.","wrong":"","symbol":"FileLastModifiedPluginOptions","correct":"import type { FileLastModifiedPluginOptions } from 'esbuild-plugin-filelastmodified'"}],"quickstart":{"code":"import { build } from 'esbuild';\nimport { fileLastModifiedPlugin } from 'esbuild-plugin-filelastmodified';\n\nawait build({\n  entryPoints: ['src/app.js'],\n  bundle: true,\n  outfile: 'dist/out.js',\n  plugins: [\n    fileLastModifiedPlugin({\n      filter: /^.*\\.json$/,\n      namespace: 'filemod',\n    }),\n  ],\n});\n\n// In your entry point, import the virtual module to get timestamps:\nimport { 'filemod:./data.json' as timestamps };\n// timestamps will be an object mapping file paths to last modified timestamps (Unix ms).","lang":"typescript","description":"Shows how to set up the esbuild plugin and use virtual module imports to get file modification timestamps."},"warnings":[{"fix":"Ensure the import path matches the namespace configuration, e.g., 'my-ns:./file.js' if namespace is 'my-ns'.","message":"Plugin expects the virtual module import path to start with the namespace prefix (default 'filemod:') — if you change the namespace, adjust imports accordingly.","severity":"gotcha","affected_versions":"*"},{"fix":"Use Math.floor(timestamp / 1000) to get seconds.","message":"Timestamps are in milliseconds (Unix time); if you need seconds, divide by 1000.","severity":"gotcha","affected_versions":"*"},{"fix":"Import the files you need timestamps for, even if they are not directly used in code.","message":"The plugin only watches files included in the esbuild build graph (via import statements). Files not imported anywhere will not have their timestamps tracked.","severity":"gotcha","affected_versions":"*"},{"fix":"Explicitly import any file you need timestamps for to ensure rebuilds trigger.","message":"Changes to the monitored files will cause esbuild to rebuild only if those files are actually part of the build (i.e., imported). The plugin does not add files to the build graph automatically.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use the correct import: import { fileLastModifiedPlugin } from 'esbuild-plugin-filelastmodified'","cause":"Importing the wrong export or using an outdated import pattern.","error":"Error: The plugin \"fileLastModifiedPlugin\" doesn't have a `setup` function."},{"fix":"Run npm install esbuild-plugin-filelastmodified --save-dev","cause":"Package not installed or missing from dependencies.","error":"Cannot find module 'esbuild-plugin-filelastmodified'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}