{"id":21265,"library":"esbuild-plugin-raw","title":"esbuild-plugin-raw","description":"An esbuild plugin that allows importing file contents as raw strings. Version 0.3.0 supports esbuild ^0.14.36 through ^0.25.0. It is a simple, zero-config plugin that attaches to esbuild's resolve and load hooks. Unlike manual readFileSync or similar, it integrates seamlessly with esbuild's build pipeline and respects loaders. Typically used for embedding text files (e.g., shaders, markdown) in bundles. Ships TypeScript declarations.","status":"active","version":"0.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/hannoeru/esbuild-plugin-raw","tags":["javascript","typescript"],"install":[{"cmd":"npm install esbuild-plugin-raw","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-raw","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-raw","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; the plugin is designed to work as an esbuild plugin.","package":"esbuild","optional":false}],"imports":[{"note":"Default export. The package is ESM-only; require() will fail unless using dynamic import or a bundler that can handle ESM.","wrong":"const RawPlugin = require('esbuild-plugin-raw')","symbol":"RawPlugin","correct":"import RawPlugin from 'esbuild-plugin-raw'"},{"note":"The plugin is exported as default, not as a named export. Named import will result in undefined.","wrong":"import { RawPlugin } from 'esbuild-plugin-raw'","symbol":"esbuild-plugin-raw","correct":"import RawPlugin from 'esbuild-plugin-raw'"},{"note":"For TypeScript, use default import with type modifier for type-only imports if not using the value.","wrong":"import { RawPlugin } from 'esbuild-plugin-raw'","symbol":"TypeScript types","correct":"import type RawPlugin from 'esbuild-plugin-raw'"}],"quickstart":{"code":"import esbuild from 'esbuild'\nimport RawPlugin from 'esbuild-plugin-raw'\n\nawait esbuild.build({\n  entryPoints: ['src/index.js'],\n  bundle: true,\n  outfile: 'dist/bundle.js',\n  plugins: [RawPlugin],\n})\n\n// Then in a source file:\n// import raw from './file.txt?raw'\n// console.log(raw) // string content","lang":"typescript","description":"Shows basic usage: import the plugin, add it to esbuild plugins array, and then import files with ?raw suffix to get their contents as a string."},"warnings":[{"fix":"Append '?raw' to all imports you want as raw strings, e.g., import data from './file.txt?raw'.","message":"Plugin only emits raw content for imports ending with '?raw'. Without the query, esbuild handles the file normally.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Add a declaration file: declare module '*?raw' { const content: string; export default content; }","message":"When using TypeScript, you may need to declare a module for '*.txt?raw' imports to avoid type errors.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Upgrade esbuild to at least v0.14.36.","message":"The plugin does not work with esbuild v0.14.x and below (peer dependency range starts at 0.14.36).","severity":"gotcha","affected_versions":"<0.14.36"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use dynamic import: const RawPlugin = (await import('esbuild-plugin-raw')).default;","cause":"The package is ESM-only. Using require() in CommonJS context throws.","error":"Error: esbuild-plugin-raw: ESM-only package. Use dynamic import or a bundler that can handle ESM."},{"fix":"Run 'npm install -D esbuild-plugin-raw esbuild'","cause":"Missing installation or peer dependency esbuild not installed.","error":"Error: Cannot find module 'esbuild-plugin-raw'"},{"fix":"Use default import: import RawPlugin from 'esbuild-plugin-raw';","cause":"Importing the default export incorrectly (e.g., named import).","error":"TypeError: RawPlugin is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}