Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
FrappeApp
✓ import { FrappeApp } from 'frappe-js-sdk'
✗ const FrappeApp = require('frappe-js-sdk')
Package is ESM-first. Using require() may cause issues in Node.js without esModuleInterop.
Auth
✓ const auth = frappe.auth()
✗ import { Auth } from 'frappe-js-sdk'
Auth is not a named export; it's obtained by calling the auth() method on FrappeApp instance.
FrappeDB
✓ const db = frappe.db()
✗ import { FrappeDB } from 'frappe-js-sdk'
FrappeDB is not directly exported; instantiate via frappe.db().
FileUpload
✓ const fileUpload = frappe.fileUpload()
✗ import { FrappeFileUpload } from 'frappe-js-sdk'
FileUpload instance is obtained from frappe.fileUpload(), not a direct export.
FrappeCall
✓ const call = frappe.call()
✗ import { FrappeCall } from 'frappe-js-sdk'
Call instance is obtained from frappe.call().
Initializes FrappeApp with optional token-based auth, logs in via credentials, performs CRUD operations on DocType documents, and calls a custom Frappe method.
import { FrappeApp } from 'frappe-js-sdk';
// Initialize with token-based auth (e.g., API key/secret or OAuth)
const frappe = new FrappeApp('https://your-frappe-site.com', {
useToken: true,
token: () => localStorage.getItem('auth_token') ?? '', // custom function to get token
type: 'Bearer' // or 'token'
});
// Or use cookie-based login:
const auth = frappe.auth();
auth.loginWithUsernamePassword({ username: 'admin', password: 'password' })
.then(() => console.log('Logged in'))
.catch(err => console.error(err));
// Fetch a document by name from the 'Customer' DocType
const db = frappe.db();
db.getDoc('Customer', 'CUST-00001')
.then(doc => console.log('Document:', doc))
.catch(err => console.error(err));
// Get a list of documents with filters
const filters = [['status', '=', 'Open']];
db.getDocList('ToDo', { fields: ['*'], filters, limit: 10 })
.then(list => console.log('List:', list))
.catch(err => console.error(err));
// Create a new document
db.createDoc('ToDo', { description: 'Test todo', status: 'Open' })
.then(doc => console.log('Created:', doc))
.catch(err => console.error(err));
// Update a document
db.updateDoc('ToDo', 'TODO-00001', { status: 'Closed' })
.then(doc => console.log('Updated:', doc))
.catch(err => console.error(err));
// Delete a document
db.deleteDoc('ToDo', 'TODO-00001')
.then(() => console.log('Deleted'))
.catch(err => console.error(err));
// Call a custom Frappe method
const call = frappe.call();
call.post('frappe.client.get_value', {
doctype: 'User',
fieldname: 'email',
filters: { name: 'Administrator' }
}).then(res => console.log(res));
Errors
Common errors & fixes
Cannot find module 'frappe-js-sdk' or its corresponding type declarations.
Package not installed or TypeScript compiler cannot resolve types.
fixRun 'npm install frappe-js-sdk' and ensure tsconfig.json includes 'node_modules' in typeRoots or skipLibCheck.
FrappeApp is not a constructor
CommonJS require() imported the module incorrectly; the default export is an object with FrappeApp property.
fixUse ES6 import: import { FrappeApp } from 'frappe-js-sdk' TypeError: Cannot read properties of undefined (reading 'getDoc')
frappe.db() was called before FrappeApp was fully initialized (e.g., missing base URL).
fixEnsure new FrappeApp('https://your-site.com') is called with a valid URL before using db(). AxiosError: Request failed with status code 403
Token auth used but the token is invalid, expired, or missing in the request headers.
fixCheck that useToken is true and token function returns a valid token string. Verify Frappe server settings.
Audit
Dependencies
axiosrequiredHTTP client used for all API calls to Frappe backend