安装inert插件后,Hapi v16.0.0报Cannot read property 'register'错误
Hey there, I’ve run into this exact compatibility issue before with older Hapi versions—let’s get it sorted out quickly!
The Root Cause
You’re using Hapi 16.0.0, but when you ran npm install --save inert, npm pulled in the latest version of Inert, which no longer supports Hapi 16. Newer Inert releases (v5 and above) are built for Hapi 17+, which completely changed the plugin registration API—this mismatch is why you’re seeing that "Cannot read property 'register' of undefined" error.
The Fix
You need to install a version of Inert that’s explicitly compatible with Hapi 16.0.0 (the 4.x series). Here’s how:
- First, uninstall the incompatible Inert version:
npm uninstall inert - Install the latest stable 4.x release of Inert:
npm install --save inert@4.2.3
Verify Your Setup
Your existing server.js code is perfectly correct for Hapi 16.0.0 and Inert 4.x—no changes needed there! Once you’ve installed the right version, restart your server:
node server.js
It should boot up without errors, and your /hello route will successfully serve the ./public/hello.html file.
Quick Version Compatibility Cheat Sheet
For future reference, Hapi and its plugins have strict version matching:
- Hapi 16.x ↔ Inert 4.x
- Hapi 17.x/18.x ↔ Inert 5.x
- Hapi 19+ ↔ Inert 6.x+
内容的提问来源于stack exchange,提问作者Jitendra

