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.
val-loader
✓ module.exports = { module: { rules: [ { test: /\.js$/, use: 'val-loader' } ] } }
✗ import valLoader from 'val-loader'
val-loader is a webpack loader, not a JavaScript module. It is configured in webpack config, not imported in source code.
target module function
✓ module.exports = (options, loaderContext) => { return { code: '...' }; }
✗ export default (options, loaderContext) => { ... }
The target file must use CommonJS (module.exports) because webpack loaders expect a function exported via module.exports.
executableFile
✓ options: { executableFile: path.resolve(__dirname, 'exec.js') }
✗ options: { executableFile: './exec.js' }
The executableFile option expects an absolute path. Relative paths may fail silently.
Shows how to configure val-loader with options and a target module that uses those options to generate code.
// target-file.js
module.exports = (options, loaderContext) => {
return { code: 'module.exports = ' + JSON.stringify(options) + ';' };
};
// webpack.config.js
const path = require('path');
module.exports = {
module: {
rules: [
{
test: /\.val\.js$/,
use: [
{
loader: 'val-loader',
options: { greeting: 'Hello, world!' }
}
]
}
]
}
};
// input.val.js
module.exports = (options, loaderContext) => {
return { code: `module.exports = "${options.greeting}";` };
};
// entry.js
const greeting = require('./input.val.js');
console.log(greeting); // 'Hello, world!'
Errors
Common errors & fixes
Error: Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.
The target file is not matching the test pattern in webpack config, or val-loader is not applied.
fixEnsure the webpack rule test matches the target file and that use: 'val-loader' is specified.
TypeError: loaderContext.addDependency is not a function
Using an outdated version of webpack or the loader context does not support addDependency.
fixUpgrade to webpack 5 and val-loader v3+.
Error: The 'val-loader' loader doesn't return an object with a 'code' property.
The target function returned an object without the required 'code' property.
fixEnsure the target function returns { code: '...' }. Module not found: Error: Can't resolve 'val-loader' in ...
val-loader is not installed as a devDependency.
fixRun 'npm install val-loader --save-dev' or equivalent.
Audit
Dependencies
webpackrequiredPeer dependency: requires webpack 5.x to function as a loader