Registry / devops / raw-loader

raw-loader

JSON →
library4.0.2jsnpmunverified

Webpack loader that imports files as a string. Current stable version 4.0.2 (2020-10-09), maintained by webpack-contrib. Supports webpack 4 and 5. Key differentiator: minimal, zero-config loader for raw text files. Alternatives like file-loader or url-loader create separate files; raw-loader inlines content as a string. Enables ES module or CommonJS output via the `esModule` option (default true, changed in v4.0.0). Requires Node >= 10.13.0.

npm install raw-loader
INSTALL
IMPORT
SIG · RAW-LOADER
R
raw-loader
devopsjavascriptv4.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

default import (string content)
import txt from './file.txt';
const txt = require('./file.txt');
Since v4.0.0, output defaults to ES modules. Use `esModule: false` for CommonJS.
inline usage with webpack
import txt from 'raw-loader!./file.txt';
import txt from 'raw-loader!./file.txt'; // but missing !! to disable other loaders
Add `!!` prefix to bypass other rules: `import txt from '!!raw-loader!./file.txt';`
webpack rule configuration
module.exports = { module: { rules: [ { test: /\.txt$/i, use: 'raw-loader' } ] } };
module.exports = { module: { rules: [ { test: /\.txt$/i, loader: 'raw-loader' } ] } };
Use `use` (or `loader` is also valid, but `use` is modern).

Configures webpack to load .txt files as strings using raw-loader.

// webpack.config.js module.exports = { module: { rules: [ { test: /\.txt$/i, use: 'raw-loader', }, ], }, }; // file.txt: Hello World // entry.js import content from './file.txt'; console.log(content); // 'Hello World'
Debug
Known issues
breakingMinimum Node.js version changed
fix
Ensure Node.js >= 10.13.0
affects: >=4.0.0
breakingES module export became default in v2.0.0
fix
For CommonJS output, set `esModule: false` in options.
affects: >=2.0.0
deprecatedThe `modules` option (renamed to `esModule`)
fix
Use `esModule` instead of `modules`.
affects: >=3.0.0
gotchaInline loader syntax may conflict with other rules
fix
Prefix with `!!` to disable all other loaders: `import txt from '!!raw-loader!./file.txt';`
affects: >=1.0.0
Errors
Common errors & fixes
Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type.
Raw-loader not configured for file extension in webpack config.
fix
Add rule: `{ test: /\.txt$/, use: 'raw-loader' }` in webpack.config.js
Cannot find module 'raw-loader'
raw-loader not installed or wrong devDependency.
fix
Run `npm install raw-loader --save-dev`
Invalid options object. Options not matching the schema defined in schema-utils
Unknown or malformed option passed to raw-loader.
fix
Check options: only `esModule` (boolean) is supported. Remove any other options like `modules` (renamed) or typos.
Upgrade
Version history
4.0.2latest on npm
Audit
Dependencies
webpackrequiredPeer dependency - required as the host bundler
schema-utilsrequiredRuntime dependency for option validation (4.x)
Agent activity
10 hits · last 30 days
node
10
Resources
raw-loader — npm install raw-loader · libregistry