Castle Email Library
raw JSON → 2.5.0 verified Sat Apr 25 auth: no javascript
A library for building emails with React, version 2.5.0. Provides components and utilities to create responsive, template-based emails using React, simplifying the process of generating HTML emails. It emphasizes a component-based approach, allowing reuse and composition, and integrates with common email sending services. Key differentiators include a focus on React developers familiar with JSX, reducing the need for traditional email template languages. Currently stable with regular updates.
Common errors
error Module not found: Can't resolve 'castle-email-lib' ↓
cause Missing package install or incorrect import path.
fix
Run
npm install castle-email-lib and use correct import: import { CastleEmail } from 'castle-email-lib'. error Uncaught TypeError: castle_email_lib_1.CastleEmail is not a constructor ↓
cause Using default import for non-default export.
fix
Use named import:
import { CastleEmail } from 'castle-email-lib'. error CastleEmail is not defined ↓
cause Undefined symbol in scope, likely due to import error or missing peer dependency.
fix
Ensure React is installed and import CastleEmail correctly.
Warnings
breaking Version 2.0.0 changed the import paths from root to subpaths. ↓
fix Update imports: `import { CastleEmail } from 'castle-email-lib'` and subpath imports for additional exports.
deprecated The default export was removed in v2.0.0. ↓
fix Use named imports instead.
gotcha EmailRenderer expects JSX element, not component class or string. ↓
fix Always pass a React element, e.g., `renderer.render(<MyComponent />)`.
breaking CJS support dropped in v2.0.0, only ESM is supported. ↓
fix Use ESM imports or upgrade build system.
Install
npm install castle-email-lib yarn add castle-email-lib pnpm add castle-email-lib Imports
- CastleEmail wrong
const { CastleEmail } = require('castle-email-lib')correctimport { CastleEmail } from 'castle-email-lib' - EmailRenderer wrong
import EmailRenderer from 'castle-email-lib'correctimport { EmailRenderer } from 'castle-email-lib/renderer' - Template wrong
import Template from 'castle-email-lib/templates'correctimport { Template } from 'castle-email-lib/templates'
Quickstart
import { CastleEmail, EmailRenderer } from 'castle-email-lib';
import React from 'react';
const MyEmail = () => (
<CastleEmail>
<h1>Hello World</h1>
</CastleEmail>
);
const renderer = new EmailRenderer();
const html = renderer.render(<MyEmail />);
console.log(html);