[Bug]: @actual-app/api does not work when bundled #1394

Closed
opened 2026-02-28 19:42:26 -06:00 by GiteaMirror · 6 comments
Owner

Originally created by @rodrigost23 on GitHub (Sep 6, 2024).

Verified issue does not already exist?

  • I have searched and found no existing issue
  • I will be providing steps how to reproduce the bug (in most cases this will also mean uploading a demo budget file)

What happened?

I was trying to use the API in a Next.js environment. But it bundles the dependencies into chunks, and when @actual/api uses "__dirname" to find the root path, it ends up in my disk root, thus not able to find the migrations folder.

It does not make sense to find a folder using __dirname as in:
61bffa3d31/packages/loot-core/src/platform/server/fs/index.electron.ts (L9-L15)

There should be a way to set this rootPath manually, maybe instead of setting the data path, as everything would be under the root path, or at least setting the migrations path.

Where are you hosting Actual?

Locally via Yarn

What browsers are you seeing the problem on?

Firefox

Operating System

Windows 11

Originally created by @rodrigost23 on GitHub (Sep 6, 2024). ### Verified issue does not already exist? - [X] I have searched and found no existing issue - [X] I will be providing steps how to reproduce the bug (in most cases this will also mean uploading a demo budget file) ### What happened? I was trying to use the API in a Next.js environment. But it bundles the dependencies into chunks, and when @actual/api uses "__dirname" to find the root path, it ends up in my disk root, thus not able to find the migrations folder. It does not make sense to find a folder using __dirname as in: https://github.com/actualbudget/actual/blob/61bffa3d31e96263664ab96b1bc11e9164ce653f/packages/loot-core/src/platform/server/fs/index.electron.ts#L9-L15 There should be a way to set this rootPath manually, maybe instead of setting the data path, as everything would be under the root path, or at least setting the migrations path. ### Where are you hosting Actual? Locally via Yarn ### What browsers are you seeing the problem on? Firefox ### Operating System Windows 11
GiteaMirror added the needs infobugAPIhelp wanted labels 2026-02-28 19:42:26 -06:00
Author
Owner

@rodrigost23 commented on GitHub (Sep 6, 2024):

Workaround for Next.js:

Edit next.config.mjs:

import CopyPlugin from 'copy-webpack-plugin';
import path from 'path';

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (config) => {
    // Change rootPath for @actual-app/api to find resources
    config.module.rules.push({
      test: /@actual-app.*\.js$/,
      loader: 'string-replace-loader',
      options: {
        search: 'let rootPath = .*?;',
        replace: `let rootPath = "${path.resolve('.next/@actual-app').replaceAll('\\', '\\\\')}"`,
        flags: 'g',
      },
    });
    // Copy @actual-app/api resources
    config.plugins.push(
      new CopyPlugin({
        patterns: [
          {
            from: 'node_modules/@actual-app/api/dist/migrations',
            to: '@actual-app/migrations',
          },
          {
            from: 'node_modules/@actual-app/api/dist/default-db.sqlite',
            to: '@actual-app/default-db.sqlite',
          },
        ],
      }),
    );
    return config;
  },
};

export default nextConfig;
@rodrigost23 commented on GitHub (Sep 6, 2024): Workaround for Next.js: Edit `next.config.mjs`: ```javascript import CopyPlugin from 'copy-webpack-plugin'; import path from 'path'; /** @type {import('next').NextConfig} */ const nextConfig = { webpack: (config) => { // Change rootPath for @actual-app/api to find resources config.module.rules.push({ test: /@actual-app.*\.js$/, loader: 'string-replace-loader', options: { search: 'let rootPath = .*?;', replace: `let rootPath = "${path.resolve('.next/@actual-app').replaceAll('\\', '\\\\')}"`, flags: 'g', }, }); // Copy @actual-app/api resources config.plugins.push( new CopyPlugin({ patterns: [ { from: 'node_modules/@actual-app/api/dist/migrations', to: '@actual-app/migrations', }, { from: 'node_modules/@actual-app/api/dist/default-db.sqlite', to: '@actual-app/default-db.sqlite', }, ], }), ); return config; }, }; export default nextConfig; ```
Author
Owner

@latetedemelon commented on GitHub (Sep 6, 2024):

@rodrigost23 I built a new script with the latest api (6.10.0) and actual version (24.9.0) and I'm seeing a consistent "Database is out of sync with migrations" error. This is both with "old" data and a brand new budget. Could it be related to your issue? If not I'll break this out.

Database is out of sync with migrations: {
  appliedIds: [
    1548957970627, 1550601598648, 1555786194328,
    1561751833510, 1567699552727, 1582384163573,
    1597756566448, 1608652596043, 1608652596044,
    1612625548236, 1614782639336, 1615745967948,
    1616167010796, 1618975177358, 1632571489012,
    1679728867040, 1681115033845, 1682974838138,
    1685007876842, 1686139660866, 1688749527273,
    1688841238000, 1691233396000, 1694438752000,
    1697046240000, 1704572023730, 1704572023731,
    1707267033000, 1712784523000, 1716359441000,
    1720310586000, 1720664867241, 1720665000000,
    1722717601000, 1722804019000
  ],
  available: [
    '1548957970627_remove-db-version.sql',
    '1550601598648_payees.sql',
    '1555786194328_remove_category_group_unique.sql',
    '1561751833510_indexes.sql',
    '1567699552727_budget.sql',
    '1582384163573_cleared.sql',
    '1597756566448_rules.sql',
    '1608652596043_parent_field.sql',
    '1608652596044_trans_views.sql',
    '1612625548236_optimize.sql',
    '1614782639336_trans_views2.sql',
    '1615745967948_meta.sql',
    '1616167010796_accounts_order.sql',
    '1618975177358_schedules.sql',
    '1632571489012_remove_cache.js',
    '1679728867040_rules_conditions.sql',
    '1681115033845_add_schedule_name.sql',
    '1682974838138_remove_payee_rules.sql',
    '1685007876842_add_category_hidden.sql',
    '1686139660866_remove_account_type.sql',
    '1688749527273_transaction_filters.sql',
    '1688841238000_add_account_type.sql'
  ]
}
Error updating Error: out-of-sync-migrations
@latetedemelon commented on GitHub (Sep 6, 2024): @rodrigost23 I built a new script with the latest api (6.10.0) and actual version (24.9.0) and I'm seeing a consistent "Database is out of sync with migrations" error. This is both with "old" data and a brand new budget. Could it be related to your issue? If not I'll break this out. ``` Database is out of sync with migrations: { appliedIds: [ 1548957970627, 1550601598648, 1555786194328, 1561751833510, 1567699552727, 1582384163573, 1597756566448, 1608652596043, 1608652596044, 1612625548236, 1614782639336, 1615745967948, 1616167010796, 1618975177358, 1632571489012, 1679728867040, 1681115033845, 1682974838138, 1685007876842, 1686139660866, 1688749527273, 1688841238000, 1691233396000, 1694438752000, 1697046240000, 1704572023730, 1704572023731, 1707267033000, 1712784523000, 1716359441000, 1720310586000, 1720664867241, 1720665000000, 1722717601000, 1722804019000 ], available: [ '1548957970627_remove-db-version.sql', '1550601598648_payees.sql', '1555786194328_remove_category_group_unique.sql', '1561751833510_indexes.sql', '1567699552727_budget.sql', '1582384163573_cleared.sql', '1597756566448_rules.sql', '1608652596043_parent_field.sql', '1608652596044_trans_views.sql', '1612625548236_optimize.sql', '1614782639336_trans_views2.sql', '1615745967948_meta.sql', '1616167010796_accounts_order.sql', '1618975177358_schedules.sql', '1632571489012_remove_cache.js', '1679728867040_rules_conditions.sql', '1681115033845_add_schedule_name.sql', '1682974838138_remove_payee_rules.sql', '1685007876842_add_category_hidden.sql', '1686139660866_remove_account_type.sql', '1688749527273_transaction_filters.sql', '1688841238000_add_account_type.sql' ] } Error updating Error: out-of-sync-migrations ```
Author
Owner

@rodrigost23 commented on GitHub (Sep 6, 2024):

Yes, I was having the same error before I used the custom webpack configuration. The problem was that the Actual API was trying to find the migrations folder that is inside the library itself, but it uses a path relative to __dirname, which is not reliable, and isn't customizable.

The workaround was to set all let rootPath = in the library's code to a folder containing the migrations folder copied from the lib.

@rodrigost23 commented on GitHub (Sep 6, 2024): Yes, I was having the same error before I used the custom webpack configuration. The problem was that the Actual API was trying to find the `migrations` folder that is inside the library itself, but it uses a path relative to __dirname, which is not reliable, and isn't customizable. The workaround was to set all `let rootPath = ` in the library's code to a folder containing the migrations folder copied from the lib.
Author
Owner

@hugh-codes commented on GitHub (Oct 7, 2024):

I am also seeing the same error when bundling the app

@hugh-codes commented on GitHub (Oct 7, 2024): I am also seeing the same error when bundling the app
Author
Owner

@MatissJanis commented on GitHub (Jun 12, 2025):

👋 Would you be able to provide a reproduction for this issue?

Thanks

@MatissJanis commented on GitHub (Jun 12, 2025): 👋 Would you be able to provide a reproduction for this issue? Thanks
Author
Owner

@github-actions[bot] commented on GitHub (Jun 20, 2025):

This issue has been automatically closed because there have been no comments for 7 days after the "needs info" label was added. If you still need help, please feel free to reopen the issue with the requested information.

@github-actions[bot] commented on GitHub (Jun 20, 2025): This issue has been automatically closed because there have been no comments for 7 days after the "needs info" label was added. If you still need help, please feel free to reopen the issue with the requested information.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#1394