{"id":"98470034dd6a8cd5","repo":"typeorm/typeorm","slug":"no-location-is-set-specify-a-location-parameter-o","errorCode":null,"errorMessage":"No location is set, specify a location parameter or add the location option to your configuration","messagePattern":"No location is set, specify a location parameter or add the location option to your configuration","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"src/driver/sqljs/SqljsDriver.ts","lineNumber":161,"sourceCode":"                }\n            }\n        } else {\n            return this.createDatabaseConnectionWithImport(\n                fileNameOrLocalStorageOrData,\n            )\n        }\n    }\n\n    /**\n     * Saved the current database to the given file (Node.js), local storage key (browser) or\n     * indexedDB key (browser with enabled useLocalForage option).\n     * If no location path is given, the location path in the options (if specified) will be used.\n     *\n     * @param location\n     */\n    async save(location?: string) {\n        if (!location && !this.options.location) {\n            throw new TypeORMError(\n                `No location is set, specify a location parameter or add the location option to your configuration`,\n            )\n        }\n\n        let path = \"\"\n        if (location) {\n            path = location\n        } else if (this.options.location) {\n            path = this.options.location\n        }\n\n        if (PlatformTools.type === \"node\") {\n            try {\n                const content = Buffer.from(this.databaseConnection.export())\n                await PlatformTools.writeFile(path, content)\n            } catch (e) {\n                throw new TypeORMError(`Could not save database, error: ${e}`)\n            }","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/src/driver/sqljs/SqljsDriver.ts#L143-L179","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\nawait driver.save();\n// after\nawait driver.save(\"./data/app.sqlite\");\n// or\nconst bytes: Uint8Array = driver.export();","handlingStrategy":"validation","validationCode":"const dest = location ?? options.location;\nif (!dest) throw new Error('No save destination - set options.location or pass a path');\nawait driver.save(dest);","typeGuard":"const hasSaveTarget = (o: SqljsDataSourceOptions, explicit?: string) =>\n  typeof explicit === 'string' || typeof o.location === 'string';","tryCatchPattern":"try { await driver.save(); }\ncatch (e) { if (e instanceof TypeORMError && /No location is set/.test(e.message)) { await driver.save('app.sqlite'); } else throw e; }","preventionTips":["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."],"tags":["sqljs","config","persistence","typeorm"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}