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
muslnode 18–226 runs
build_error
glibcnode 18–226 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'
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.
fixAdd rule: `{ test: /\.txt$/, use: 'raw-loader' }` in webpack.config.js Cannot find module 'raw-loader'
raw-loader not installed or wrong devDependency.
fixRun `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.
fixCheck options: only `esModule` (boolean) is supported. Remove any other options like `modules` (renamed) or typos.
Audit
Dependencies
webpackrequiredPeer dependency - required as the host bundler
schema-utilsrequiredRuntime dependency for option validation (4.x)