Skip to content

Commit

Permalink
fix: error message on not installed module loaders for configuration (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 31, 2020
1 parent d6380bb commit 29eaa8e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -717,7 +717,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
@@ -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
@@ -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;

0 comments on commit 29eaa8e

Please sign in to comment.