From 8e5a05b993998c2c20d4ba159926114f0c0a884e Mon Sep 17 00:00:00 2001 From: Ben Demboski Date: Tue, 27 Apr 2021 10:14:09 -0700 Subject: [PATCH] Better error message with webpack v4 installed Detect when a too-old version of webpack is installed upfront, rather than producing a more cryptic error later in the build process when some incompatible data is encountered. --- packages/webpack/package.json | 1 + packages/webpack/src/ember-webpack.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/packages/webpack/package.json b/packages/webpack/package.json index 24af40eb6..fba55e6b6 100644 --- a/packages/webpack/package.json +++ b/packages/webpack/package.json @@ -39,6 +39,7 @@ "lodash": "^4.17.10", "mini-css-extract-plugin": "^1.3.2", "pkg-up": "^3.1.0", + "semver": "^7.3.5", "source-map-url": "^0.4.0", "style-loader": "^2.0.0", "terser": "^5.5.1", diff --git a/packages/webpack/src/ember-webpack.ts b/packages/webpack/src/ember-webpack.ts index 9f16e89ce..d2dc34445 100644 --- a/packages/webpack/src/ember-webpack.ts +++ b/packages/webpack/src/ember-webpack.ts @@ -26,6 +26,7 @@ import { HTMLEntrypoint } from './html-entrypoint'; import { StatSummary } from './stat-summary'; import crypto from 'crypto'; import type { HbsLoaderConfig } from '@embroider/hbs-loader'; +import semverSatisfies from 'semver/functions/satisfies'; const debug = makeDebug('embroider:debug'); @@ -83,6 +84,10 @@ const Webpack: Packager = class Webpack implements PackagerInstance { private consoleWrite: (msg: string) => void, options?: Options ) { + if (!semverSatisfies(webpack.version, '^5.0.0')) { + throw new Error(`@embroider/webpack requires webpack@^5.0.0, but found version ${webpack.version}`); + } + this.pathToVanillaApp = realpathSync(pathToVanillaApp); this.extraConfig = options?.webpackConfig; this.publicAssetURL = options?.publicAssetURL;