Skip to content

Commit 285980e

Browse files
committed
fix: do not ignoring webpack config loading errors
1 parent 28bbb72 commit 285980e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

actions/build.action.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from '../lib/configuration/defaults';
2323
import { FileSystemReader } from '../lib/readers';
2424
import { ERROR_PREFIX } from '../lib/ui';
25+
import { isModuleAvailable } from '../lib/utils/is-module-available';
2526
import { AbstractAction } from './abstract.action';
2627
import webpack = require('webpack');
2728

@@ -261,13 +262,15 @@ export class BuildAction extends AbstractAction {
261262
webpackRef: typeof webpack,
262263
) => webpack.Configuration {
263264
const pathToWebpackFile = join(process.cwd(), webpackPath);
265+
const isWebpackFileAvailable = isModuleAvailable(pathToWebpackFile);
266+
if (!isWebpackFileAvailable && webpackPath === defaultPath) {
267+
return ({}) => ({});
268+
}
269+
264270
try {
265271
return require(pathToWebpackFile);
266272
} catch (err) {
267-
if (webpackPath !== defaultPath) {
268-
throw err;
269-
}
270-
return ({}) => ({});
273+
throw err;
271274
}
272275
}
273276
}

lib/utils/is-module-available.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function isModuleAvailable(path: string): boolean {
2+
try {
3+
require.resolve(path);
4+
return true;
5+
} catch {
6+
return false;
7+
}
8+
}

0 commit comments

Comments
 (0)