server-only package throw error tại build time nếu vô tình import server code vào client bundle. client-only throw nếu import client code trên server.
- Dùng:
import 'server-only'đầu file chứa database connections, API keys. - Giúp catch mistakes sớm thay vì runtime errors hay security issues.
The server-only package throws a build-time error if server code is accidentally imported into the client bundle. client-only throws if client code is imported on the server.
- Usage: add
import 'server-only'at the top of files containing database connections or API keys. - This catches mistakes early rather than discovering them as runtime errors or security vulnerabilities.