typeorm/typeorm · error · TypeORMError
No location is set, specify a location parameter or add the
Error message
No location is set, specify a location parameter or add the location option to your configuration
What it means
Thrown by SqljsDriver.save() when neither an explicit `location` argument nor options.location is set. save() needs a destination to write the exported Uint8Array to (file path in Node, storage key in browser); without one there is nothing to persist to and the call is meaningless.
Source
Thrown at src/driver/sqljs/SqljsDriver.ts:161
}
}
} else {
return this.createDatabaseConnectionWithImport(
fileNameOrLocalStorageOrData,
)
}
}
/**
* Saved the current database to the given file (Node.js), local storage key (browser) or
* indexedDB key (browser with enabled useLocalForage option).
* If no location path is given, the location path in the options (if specified) will be used.
*
* @param location
*/
async save(location?: string) {
if (!location && !this.options.location) {
throw new TypeORMError(
`No location is set, specify a location parameter or add the location option to your configuration`,
)
}
let path = ""
if (location) {
path = location
} else if (this.options.location) {
path = this.options.location
}
if (PlatformTools.type === "node") {
try {
const content = Buffer.from(this.databaseConnection.export())
await PlatformTools.writeFile(path, content)
} catch (e) {
throw new TypeORMError(`Could not save database, error: ${e}`)
}View on GitHub (pinned to 04ff4daedc)
Solutions
- Pass an explicit path/key to save(): await driver.save("./data/app.sqlite").
- Set `location` in the DataSource options so save() has a default destination.
- If you want the bytes rather than a file write, call driver.export() instead of save().
- If using autoSaveCallback, ensure options.autoSaveCallback is set — that path bypasses save() entirely.
Example fix
// before
await driver.save();
// after
await driver.save("./data/app.sqlite");
// or
const bytes: Uint8Array = driver.export(); Defensive patterns
Strategy: validation
Validate before calling
const dest = location ?? options.location;
if (!dest) throw new Error('No save destination - set options.location or pass a path');
await driver.save(dest); Type guard
const hasSaveTarget = (o: SqljsDataSourceOptions, explicit?: string) => typeof explicit === 'string' || typeof o.location === 'string';
Try / catch
try { await driver.save(); }
catch (e) { if (e instanceof TypeORMError && /No location is set/.test(e.message)) { await driver.save('app.sqlite'); } else throw e; } Prevention
- Always set options.location so save() has a default destination.
- Pass an explicit path/key to save() when calling manually.
- Use driver.export() if you want bytes rather than a file write.
When it happens
Trigger: Calling driver.save() with no argument when options.location was never set; calling driver.save() after constructing a DataSource that only had `database` (seed bytes) and no `location`; autoSave triggering save() after the user cleared options.location.
Common situations: Memory-only sqljs usage where the developer calls save() expecting it to return bytes (it doesn't — that is export()); forgot to set location in options; autoSave enabled but neither location nor autoSaveCallback configured (constructor normally catches this, but a save() call from manual code path also hits this guard).
Related errors
- Driver option (location or autoSaveCallback) is not set. Ple
- File ${fileNameOrLocalStorageOrData} does not exist
- localforage is not defined - please import localforage.js in
- Can not clear database. No database is specified
- Could not save database, error: ${e}
AI-assisted analysis of typeorm/typeorm@04ff4daedc (2026-08-03).
Data as JSON: /data/errors/98470034dd6a8cd5.json.
Report an issue: GitHub.