ionic-team / ionic-team/capacitor
[Bug]: capacitor.config.js not working
- Dominant language
- TypeScript
- Stars
- 16.7k
- Forks
- 1.3k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 10
Description
### 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
```Shell
npm --version
10.9.2
node -v
v22.15.1
```
### Platforms Affected
- [x] iOS
- [x] Android
- [x] Web
### Current Behavior
capacitor.config.js has export default config object, but cli processed it wrong way:
`capacitor.config.js`
```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:
```sh
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 https://github.com/ionic-team/capacitor/blob/5b27fdf44a924f6aaf9b15555999bc839e7bfe81/cli/src/config.ts#L143.
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: https://github.com/ionic-team/capacitor/blob/5b27fdf44a924f6aaf9b15555999bc839e7bfe81/cli/src/config.ts#L116.
### 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_
Contributor guide
Assessment
This issue has not been assessed yet.