Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/webpack-cli/lib/webpack-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,23 @@ class WebpackCLI {
const interpreted = Object.keys(jsVariants).find((variant) => variant === ext);

if (interpreted) {
rechoir.prepare(extensions, configPath);
try {
rechoir.prepare(extensions, configPath);
} catch (error) {
if (error.failures) {
logger.error(`Unable load '${configPath}'`);
logger.error(error.message);

error.failures.forEach((failure) => {
logger.error(failure.error.message);
});
logger.error('Please install one of them');
process.exit(2);
}

logger.error(error);
process.exit(2);
}
}

const { pathToFileURL } = require('url');
Expand Down
19 changes: 19 additions & 0 deletions test/config-format/failure/failure.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const path = require('path');

const { run } = require('../../utils/test-utils');

describe('webpack cli', () => {
it('should support mjs config format', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['-c', 'webpack.config.coffee']);

expect(exitCode).toBe(2);
expect(stderr).toContain(`Unable load '${path.resolve(__dirname, './webpack.config.coffee')}'`);
expect(stderr).toContain('Unable to use specified module loaders for ".coffee".');
expect(stderr).toContain("Cannot find module 'coffeescript/register'");
expect(stderr).toContain("Cannot find module 'coffee-script/register'");
expect(stderr).toContain("Cannot find module 'coffeescript'");
expect(stderr).toContain("Cannot find module 'coffee-script'");
expect(stderr).toContain('Please install one of them');
expect(stdout).toBeFalsy();
});
});
10 changes: 10 additions & 0 deletions test/config-format/failure/webpack.config.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
path = require 'path'

config =
mode: 'production'
entry: './main.js'
output:
path: path.resolve(__dirname, 'dist')
filename: 'foo.bundle.js'

module.exports = config;