Registry / devops / esbuild-plugin-raw

esbuild-plugin-raw

JSON →
library0.3.0jsnpmunverified

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.

npm install esbuild-plugin-raw
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-RAW
E
esbuild-plugin-raw
devopsjavascriptv0.3.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RawPlugin
✓ import RawPlugin from 'esbuild-plugin-raw'
✗ const RawPlugin = require('esbuild-plugin-raw')
Default export. The package is ESM-only; require() will fail unless using dynamic import or a bundler that can handle ESM.
esbuild-plugin-raw
✓ import RawPlugin from 'esbuild-plugin-raw'
✗ import { RawPlugin } from 'esbuild-plugin-raw'
The plugin is exported as default, not as a named export. Named import will result in undefined.
TypeScript types
✓ import type RawPlugin from 'esbuild-plugin-raw'
✗ import { RawPlugin } from 'esbuild-plugin-raw'
For TypeScript, use default import with type modifier for type-only imports if not using the value.

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.

import esbuild from 'esbuild' import RawPlugin from 'esbuild-plugin-raw' await esbuild.build({ entryPoints: ['src/index.js'], bundle: true, outfile: 'dist/bundle.js', plugins: [RawPlugin], }) // Then in a source file: // import raw from './file.txt?raw' // console.log(raw) // string content
Debug
Known issues
gotchaPlugin only emits raw content for imports ending with '?raw'. Without the query, esbuild handles the file normally.
fix
Append '?raw' to all imports you want as raw strings, e.g., import data from './file.txt?raw'.
affects: >=0.0.0
gotchaWhen using TypeScript, you may need to declare a module for '*.txt?raw' imports to avoid type errors.
fix
Add a declaration file: declare module '*?raw' { const content: string; export default content; }
affects: >=0.0.0
gotchaThe plugin does not work with esbuild v0.14.x and below (peer dependency range starts at 0.14.36).
fix
Upgrade esbuild to at least v0.14.36.
affects: <0.14.36
Errors
Common errors & fixes
Error: esbuild-plugin-raw: ESM-only package. Use dynamic import or a bundler that can handle ESM.
The package is ESM-only. Using require() in CommonJS context throws.
fix
Use dynamic import: const RawPlugin = (await import('esbuild-plugin-raw')).default;
Error: Cannot find module 'esbuild-plugin-raw'
Missing installation or peer dependency esbuild not installed.
fix
Run 'npm install -D esbuild-plugin-raw esbuild'
TypeError: RawPlugin is not a function
Importing the default export incorrectly (e.g., named import).
fix
Use default import: import RawPlugin from 'esbuild-plugin-raw';
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies
esbuildrequiredPeer dependency; the plugin is designed to work as an esbuild plugin.
Agent activity
4 hits · last 30 days
node
4
Resources
esbuild-plugin-raw — npm install esbuild-plugin-raw · libregistry