{"id":20540,"library":"script-loader","title":"script-loader","description":"A webpack loader that executes JavaScript files once in the global context, useful for loading legacy scripts or libraries that pollute the global scope. Current stable version is 0.7.2, last released September 2017. This loader is part of the webpack-contrib organization and has minimal dependencies. It differs from imports-loader or expose-loader by executing scripts directly, without module wrapping. Does not work in Node.js; designed exclusively for browser bundles. The project is effectively in maintenance mode with no recent updates.","status":"maintenance","version":"0.7.2","language":"javascript","source_language":"en","source_url":"https://github.com/webpack-contrib/script-loader","tags":["javascript"],"install":[{"cmd":"npm install script-loader","lang":"bash","label":"npm"},{"cmd":"yarn add script-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add script-loader","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Use as a webpack loader via inline import or in webpack.config.js rules.","wrong":"import exec from './script.js'; // no loader","symbol":"default import (webpack loader)","correct":"import exec from 'script-loader!./script.js';"},{"note":"CommonJS require works as well.","wrong":"const exec = require('./script.js'); // missing script-loader","symbol":"require with loader","correct":"const exec = require('script-loader!./script.js');"},{"note":"Configure via module.rules for files matching pattern like *.exec.js.","wrong":"use: ['script-loader?'] // no query params supported","symbol":"webpack.config.js rule","correct":"use: ['script-loader']"}],"quickstart":{"code":"# Install\nnpm install --save-dev script-loader\n\n# webpack.config.js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.exec\\.js$/,\n        use: ['script-loader']\n      }\n    ]\n  }\n};\n\n# Example script.js\n// script.exec.js or import with script-loader! prefix\n// This file runs in global context\nvar globalVar = 'I am global';","lang":"javascript","description":"Configures script-loader to execute .exec.js files in the global context. Shows installation, webpack config, and a sample script that sets a global variable."},"warnings":[{"fix":"Do not use script-loader in Node.js. If needed, consider node-specific alternatives or dynamic require.","message":"script-loader does not work in Node.js; it is intended for browser bundles only.","severity":"gotcha","affected_versions":">=0.7.0"},{"fix":"Use script-loader only for scripts that intentionally pollute global scope (e.g., jQuery plugins). Use 'use strict' to prevent accidental globals.","message":"Scripts loaded with script-loader are executed in the global context, not in module scope. Variables declared without var/let/const will leak to window.","severity":"gotcha","affected_versions":">=0.7.0"},{"fix":"If you need options, consider using 'imports-loader' or 'expose-loader' instead.","message":"Script loader does not support query parameters; all configuration must be done via webpack config rules.","severity":"gotcha","affected_versions":">=0.7.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure the file path is correct and webpack can resolve it. For inline usage, verify the path after 'script-loader!'.","cause":"The loader is being used on a file that doesn't exist or is not properly resolved.","error":"Module build failed: TypeError: Cannot read property 'replace' of undefined"},{"fix":"Load dependencies in the correct order using multiple rules or ensure the global environment includes the needed definitions (e.g., via expose-loader).","cause":"The script expects certain global variables to exist before execution, but they are not defined.","error":"Uncaught ReferenceError: <variable> is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}