Skip to content

[Bug]: capacitor.config.js not working #8267

@boomfly

Description

@boomfly

Capacitor Version

💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 7.4.4
@capacitor/core: 7.4.4
@capacitor/android: 7.4.4
@capacitor/ios: 7.4.4

Installed Dependencies:

@capacitor/cli: 7.4.4
@capacitor/core: 7.4.4
@capacitor/ios: 7.4.4
@capacitor/android: 7.4.4

[success] iOS looking great! 👌
[success] Android looking great! 👌

Other API Details

npm --version
10.9.2

node -v
v22.15.1

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

capacitor.config.js has export default config object, but cli processed it wrong way:

capacitor.config.js

const isProduction = process.env.CAP_ENV == 'production' ? true : false;

const config = {
  appId: 'com.svelte.app',
  appName: 'SvelteCap',
  webDir: 'build/frontend',
  // server добавляем только если включен режим разработки
  server: !isProduction ? {
    url: 'http://192.168.1.102:5173',
    cleartext: true
  } : undefined,
  plugins: {
    Geolocation: {
      enabled: true
    }
  }
};

export default config;

Try to run cap sync cmd:

npx cap sync
[error] Could not find the web assets directory: ./www.
        Please create it and make sure it has an index.html file. You can change the path of this directory in
        capacitor.config.js (webDir option). You may need to compile the web assets for your app (typically npm run
        build). More info: https://capacitorjs.com/docs/basics/workflow#sync-your-project

The issue lies here

extConfig: await require(extConfigFilePath),
.

await require() returns object like this: {default: {/* config object */}.

To fix this we need to get same config require as TS version do, this line:

const extConfig = extConfigObject.default ? await extConfigObject.default : extConfigObject;
.

Expected Behavior

capacitor.config.js should work as expected, i change for example webDir config and cli start to sync new folder.

Project Reproduction

https://github.com/boomfly/capacitor-config-js-issue

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions