Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: top level await in capacitor.config.ts not working #6836

Closed
ximex opened this issue Aug 24, 2023 · 4 comments
Closed

bug: top level await in capacitor.config.ts not working #6836

ximex opened this issue Aug 24, 2023 · 4 comments
Labels
needs reproduction needs reproducible example to illustrate the issue platform: android platform: ios

Comments

@ximex
Copy link

ximex commented Aug 24, 2023

Bug Report

Capacitor Version

Latest Dependencies:

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

Installed Dependencies:

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

Platform(s)

ios, android

Current Behavior

if i want to use a top level await in capacitor.config.ts for an import of another file i got an error.
i run: npx --theme=xxxx cap sync

Expected Behavior

that a top level await works.

Code Reproduction

the import statement is:
const themeConfig = await import(`./src/theme/${process.env.npm_config_theme}/config`);

in the package.json the prop type is set to module

Other Technical Details

npm --version output: 8.18.0

node --version output: 18.8.0

Additional Context

The stack trace of the error:

[error] Parsing capacitor.config.ts failed.
        
        /home/xxx/project/capacitor.config.ts:41
        const themeConfig = await Promise.resolve(`${`./src/theme/${process.env.npm_config_theme}/config`}`).then(s =>
        __importStar(require(s)));
        ^^^^^
        
        SyntaxError: await is only valid in async functions and the top level bodies of modules
        at Object.compileFunction (node:vm:360:18)
        at wrapSafe (node:internal/modules/cjs/loader:1048:15)
        at Module._compile (node:internal/modules/cjs/loader:1083:27)
        at require.extensions..ts
        (/home/thomas/develop/roc-web-app/node_modules/@capacitor/cli/dist/util/node.js:34:72)
        at Module.load (node:internal/modules/cjs/loader:997:32)
        at Module._load (node:internal/modules/cjs/loader:838:12)
        at Module.require (node:internal/modules/cjs/loader:1021:19)
        at require (node:internal/modules/cjs/helpers:103:18)
        at requireTS
        (/home/thomas/develop/roc-web-app/node_modules/@capacitor/cli/dist/util/node.js:36:15)
        at loadExtConfigTS
        (/home/thomas/develop/roc-web-app/node_modules/@capacitor/cli/dist/config.js:89:54)
@ximex
Copy link
Author

ximex commented Aug 24, 2023

i also try to do this changes: #4299
but didn't solve the problem

@jcesarmobile jcesarmobile added the needs reproduction needs reproducible example to illustrate the issue label Aug 25, 2023
@ionitron-bot
Copy link

ionitron-bot bot commented Aug 25, 2023

This issue needs more information before it can be addressed. In particular, the reporter needs to provide a minimal sample app that demonstrates the issue. If no sample app is provided within 15 days, the issue will be closed.
Please see the Contributing Guide for how to create a Sample App.
Thanks! Ionitron 💙

@Ionitron Ionitron added needs reply needs reply from the user and removed needs reply needs reply from the user labels Aug 25, 2023
@jcesarmobile jcesarmobile added the needs reply needs reply from the user label Aug 28, 2023
@Ionitron
Copy link
Collaborator

It looks like this issue didn't get the information it needed, so I'll close it for now. If I made a mistake, sorry! I am just a bot.

Have a great day!
Ionitron 💙

@ionitron-bot
Copy link

ionitron-bot bot commented Oct 26, 2023

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Oct 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs reproduction needs reproducible example to illustrate the issue platform: android platform: ios
Projects
None yet
Development

No branches or pull requests

3 participants