Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(core): show friendly error for unsupported Node.js versions (#41050)

Simon Knottee5a51e730b5
diff --git a/packages/playwright-core/index.js b/packages/playwright-core/index.js
index e845cfae9f..9fc51a4d89 100644
--- a/packages/playwright-core/index.js
+++ b/packages/playwright-core/index.js
@@ -13,20 +13,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-const minimumMajorNodeVersion = 18;
-const currentNodeVersion = process.versions.node;
-const semver = currentNodeVersion.split('.');
-const [major] = [+semver[0]];
-
-if (major < minimumMajorNodeVersion) {
- console.error(
- 'You are running Node.js ' +
- currentNodeVersion +
- '.\n' +
- `Playwright requires Node.js ${minimumMajorNodeVersion} or higher. \n` +
- 'Please update your version of Node.js.'
- );
- process.exit(1);
-}
-
+require('./lib/bootstrap');
module.exports = require('./lib/coreBundle').inprocess.playwright;
diff --git a/packages/playwright-core/src/bootstrap.ts b/packages/playwright-core/src/bootstrap.ts
index 7ca2fa35c4..5e611c75c8 100644
--- a/packages/playwright-core/src/bootstrap.ts
+++ b/packages/playwright-core/src/bootstrap.ts
@@ -14,6 +14,23 @@
* limitations under the License.
*/
+const minimumMajorNodeVersion = 18;
+const currentNodeVersion = process.versions.node;
+const major = +currentNodeVersion.split('.')[0];
+
+if (major < minimumMajorNodeVersion) {
+ // eslint-disable-next-line no-console
+ console.error(
+ 'You are running Node.js ' +
+ currentNodeVersion +
+ '.\n' +
+ `Playwright requires Node.js ${minimumMajorNodeVersion} or higher. \n` +
+ 'Please update your version of Node.js.'
+ );
+ // eslint-disable-next-line no-restricted-properties
+ process.exit(1);
+}
+
if (process.env.PW_INSTRUMENT_MODULES) {
const Module = require('module');
const originalLoad = Module._load;