Skip to content

Commit 29eaa8e

Browse files
fix: error message on not installed module loaders for configuration (#2282)
1 parent d6380bb commit 29eaa8e

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

packages/webpack-cli/lib/webpack-cli.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,23 @@ class WebpackCLI {
717717
const interpreted = Object.keys(jsVariants).find((variant) => variant === ext);
718718

719719
if (interpreted) {
720-
rechoir.prepare(extensions, configPath);
720+
try {
721+
rechoir.prepare(extensions, configPath);
722+
} catch (error) {
723+
if (error.failures) {
724+
logger.error(`Unable load '${configPath}'`);
725+
logger.error(error.message);
726+
727+
error.failures.forEach((failure) => {
728+
logger.error(failure.error.message);
729+
});
730+
logger.error('Please install one of them');
731+
process.exit(2);
732+
}
733+
734+
logger.error(error);
735+
process.exit(2);
736+
}
721737
}
722738

723739
const { pathToFileURL } = require('url');
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const path = require('path');
2+
3+
const { run } = require('../../utils/test-utils');
4+
5+
describe('webpack cli', () => {
6+
it('should support mjs config format', () => {
7+
const { exitCode, stderr, stdout } = run(__dirname, ['-c', 'webpack.config.coffee']);
8+
9+
expect(exitCode).toBe(2);
10+
expect(stderr).toContain(`Unable load '${path.resolve(__dirname, './webpack.config.coffee')}'`);
11+
expect(stderr).toContain('Unable to use specified module loaders for ".coffee".');
12+
expect(stderr).toContain("Cannot find module 'coffeescript/register'");
13+
expect(stderr).toContain("Cannot find module 'coffee-script/register'");
14+
expect(stderr).toContain("Cannot find module 'coffeescript'");
15+
expect(stderr).toContain("Cannot find module 'coffee-script'");
16+
expect(stderr).toContain('Please install one of them');
17+
expect(stdout).toBeFalsy();
18+
});
19+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
path = require 'path'
2+
3+
config =
4+
mode: 'production'
5+
entry: './main.js'
6+
output:
7+
path: path.resolve(__dirname, 'dist')
8+
filename: 'foo.bundle.js'
9+
10+
module.exports = config;

0 commit comments

Comments
 (0)