shebang-loader
raw JSON → 0.0.1 verified Sat Apr 25 auth: no javascript deprecated
Webpack loader that strips the shebang (#!) line from script files, allowing them to be bundled as modules. Current version 0.0.1 is a minimal, unmaintained package with no releases since 2014. It only works with webpack 1.x and provides no configuration options. Not suitable for modern projects; alternatives include inline loader syntax or manual file transforms.
Common errors
error Module not found: Error: Can't resolve 'shebang-loader' ↓
cause shebang-loader is not installed or the loader name is misspelled.
fix
Run 'npm install shebang-loader --save-dev' and use correct loader name: 'shebang-loader' (not 'shebang').
error Error: Shebang loader is used but the file does not have a shebang ↓
cause The loader expects a shebang line; if missing, it may error (depends on implementation).
fix
Ensure files have a shebang line, or remove the loader rule for files without shebangs.
error BREAKING CHANGE: webpack < 5 used to include polyfills for node.js built-in modules... ↓
cause Using shebang-loader with modern webpack may trigger compatibility warnings due to polyfill removal.
fix
Use webpack 1 or avoid shebang-loader; it is not maintained for newer webpack versions.
Warnings
gotcha The shebang-loader only works with webpack 1.x. In webpack 2+, it is not officially supported and may cause errors. ↓
fix Use webpack 1 or manually strip shebang with a preprocessor. Consider using a custom loader or the 'imports-loader' with shebang removal.
deprecated Package has no updates since 2014 and is effectively abandoned. It does not support modern webpack versions (2, 3, 4, 5). ↓
fix Replace with a custom webpack loader that uses regex to remove shebang lines, or use an alternative package like 'strip-loader'.
gotcha The loader only strips lines that start with '#!', but does not handle files that have no shebang, causing no issues. However, it may not remove carriage return characters on Windows line endings. ↓
fix If on Windows, ensure line endings are Unix-style (LF) or modify the loader to handle CRLF.
Install
npm install shebang-loader yarn add shebang-loader pnpm add shebang-loader Imports
- default (loader) wrong
import script from 'shebang!./file.js';correctimport script from 'shebang-loader!./file.js'; - shebang-loader (config entry) wrong
module.exports = { module: { loaders: [ { test: /\.js$/, loader: 'shebang-loader' } ] } }correctmodule.exports = { module: { rules: [ { test: /\.js$/, use: 'shebang-loader' } ] } } - require (CommonJS) wrong
var script = require('shebang!./file.js');correctvar script = require('shebang-loader!./file.js');
Quickstart
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.js$/,
use: 'shebang-loader'
}
]
}
};
// Now require a CLI script with a shebang line
// bin/hello.js: #!/usr/bin/env node\nconsole.log('Hello');
const hello = require('shebang-loader!./bin/hello.js');
console.log(hello); // 'Hello'