Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error message on not installed module loaders for configuration #2282

Merged
merged 1 commit into from
Dec 31, 2020
Merged
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
@@ -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');
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;