{"id":20489,"library":"raw-loader","title":"raw-loader","description":"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.","status":"active","version":"4.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/webpack-contrib/raw-loader","tags":["javascript","webpack"],"install":[{"cmd":"npm install raw-loader","lang":"bash","label":"npm"},{"cmd":"yarn add raw-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add raw-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency - required as the host bundler","package":"webpack","optional":false},{"reason":"Runtime dependency for option validation (4.x)","package":"schema-utils","optional":false}],"imports":[{"note":"Since v4.0.0, output defaults to ES modules. Use `esModule: false` for CommonJS.","wrong":"const txt = require('./file.txt');","symbol":"default import (string content)","correct":"import txt from './file.txt';"},{"note":"Add `!!` prefix to bypass other rules: `import txt from '!!raw-loader!./file.txt';`","wrong":"import txt from 'raw-loader!./file.txt'; // but missing !! to disable other loaders","symbol":"inline usage with webpack","correct":"import txt from 'raw-loader!./file.txt';"},{"note":"Use `use` (or `loader` is also valid, but `use` is modern).","wrong":"module.exports = { module: { rules: [ { test: /\\.txt$/i, loader: 'raw-loader' } ] } };","symbol":"webpack rule configuration","correct":"module.exports = { module: { rules: [ { test: /\\.txt$/i, use: 'raw-loader' } ] } };"}],"quickstart":{"code":"// webpack.config.js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.txt$/i,\n        use: 'raw-loader',\n      },\n    ],\n  },\n};\n\n// file.txt: Hello World\n// entry.js\nimport content from './file.txt';\nconsole.log(content); // 'Hello World'","lang":"javascript","description":"Configures webpack to load .txt files as strings using raw-loader."},"warnings":[{"fix":"Ensure Node.js >= 10.13.0","message":"Minimum Node.js version changed","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"For CommonJS output, set `esModule: false` in options.","message":"ES module export became default in v2.0.0","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use `esModule` instead of `modules`.","message":"The `modules` option (renamed to `esModule`)","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Prefix with `!!` to disable all other loaders: `import txt from '!!raw-loader!./file.txt';`","message":"Inline loader syntax may conflict with other rules","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add rule: `{ test: /\\.txt$/, use: 'raw-loader' }` in webpack.config.js","cause":"Raw-loader not configured for file extension in webpack config.","error":"Module parse failed: Unexpected token (1:0)\nYou may need an appropriate loader to handle this file type."},{"fix":"Run `npm install raw-loader --save-dev`","cause":"raw-loader not installed or wrong devDependency.","error":"Cannot find module 'raw-loader'"},{"fix":"Check options: only `esModule` (boolean) is supported. Remove any other options like `modules` (renamed) or typos.","cause":"Unknown or malformed option passed to raw-loader.","error":"Invalid options object. Options not matching the schema defined in schema-utils"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}