Error: You can't use the 'await' keyword in this context

I encountered a strange issue while using a CLI that reads the capacitor.config.ts file. Every time the CLI reads the file, it throws a "ReferenceError: await is not defined" error. Interestingly, I faced a similar error with Vite in the past but cannot replicate it now.

import type {AppConfig} from '../../utils/app-config';
import {resolveAllConfigs} from '../../utils/app-config';
import type {CapacitorConfig} from '@capacitor/cli';

const appConfig: AppConfig = (await resolveAllConfigs({}));

export default ({} as CapacitorConfig);
[error] Parsing capacitor.config.ts failed.
        
        ReferenceError: await is not defined
        at Object.<anonymous>
        (/Users/oliver/Desktop/temp/app-mobile/mobile/packages/app/capacitor.config.ts:4:19)
        at Module._compile (node:internal/modules/cjs/loader:1256:14)
        at require.extensions..ts
        (/Users/oliver/Desktop/temp/app-mobile/mobile/node_modules/.pnpm/@<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1a797b6a7b79736e7568317976735a2f342e342b">[email protected]</a>/node_modules/@capacitor/cli/dist/util/node.js:34:72)
        at Module.load (node:internal/modules/cjs/loader:1119:32)
        at Module._load (node:internal/modules/cjs/loader:960:12)
        at Module.require (node:internal/modules/cjs/loader:1143:19)
        at require (node:internal/modules/cjs/helpers:121:18)
        at requireTS
        (/Users/oliver/Desktop/temp/app-mobile/mobile/node_modules/.pnpm/@<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0c3c1d0c1c3c9d4cfd28bc3ccc9e0958e948e91">[email protected]</a>/node_modules/@capacitor/cli/dist/util/node.js:36:15)
        at loadExtConfigTS
        (/Users/oliver/Desktop/temp/app-mobile/mobile/node_modules/.pnpm/@<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4625273627252f3229346d252a2f067368726877">[email protected]</a>/node_modules/@capacitor/cli/dist/config.js:89:54)
        at loadExtConfig
        (/Users/oliver/Desktop/temp/app-mobile/mobile/node_modules/.pnpm/@<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2e4d4f5e4f4d475a415c054d42476e1b001a001f">[email protected]</a>/node_modules/@capacitor/cli/dist/config.js:123:16)
import type {AppConfig, AppConfigEnv} from './app-config';
import * as cc from 'cosmiconfig';
import {TypeScriptLoader} from 'cosmiconfig-typescript-loader';
import _ from 'lodash';

const COSMICONFIG_LOADERS: cc.Loaders = {'.ts': TypeScriptLoader()};

const resolveConfig = (async(moduleName: string, env: AppConfigEnv): Promise<AppConfig> => {
  const explorer: cc.PublicExplorer = cc.cosmiconfig(moduleName, {loaders: COSMICONFIG_LOADERS});
  const result: (cc.CosmiconfigResult | null) = (await explorer.search());

  if(!result) {
    throw (new Error(`Could not find a valid ${moduleName} configuration.`));
  }

  if((typeof result.config === 'object')) {
    // Object or Promise.

    return (await result.config);
  } else if((typeof result.config === 'function')) {
    // Function.

    return (await result.config(env));
  }

  throw (new Error(`Invalid ${moduleName} configuration.`));
});

const resolveAllConfigs = (async(env: AppConfigEnv): Promise<AppConfig> => {
  const isDevelopment: boolean = (env.mode === 'development');

  return _.merge(
      (await resolveConfig('app', env)),
      ...(isDevelopment ? [
        (await resolveConfig('app--local-default', env)),
        (await resolveConfig('app--local', env))
      ] : [])
  );
});

export {
  resolveConfig,
  resolveAllConfigs
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve the date for the chosen time slot by utilizing the fullCalendar feature

I've been experiencing issues with a piece of code that is supposed to retrieve the date corresponding to a user-selected slot. Here's what I've tried so far: $('.fc-agenda-axis.fc-widget-header').on('mousedown', functio ...

Vue.js variable routes present an issue where the Favicon fails to appear

I've successfully set my favicon in the index.html file for my Vue webpack SPA. It displays properly when I visit the main site or any standard route, but it fails to show up when I navigate to a dynamic route (path: "/traduzione/:translation"). I&ap ...

Embed a function within a string literal and pass it to another component

Is there a way to pass a function defined in actions to an element? Reducer case 'UPDATE_HEADER': return Object.assign({}, state, { headerChildren: state.headerChildren.concat([action.child]) }); Action.js export const deleteH ...

Jquery trigger causing href links to malfunction

Here is a JavaScript example: var sampleFunction = function(){ return { initialize : function(data) { this.sendRequest({ action : 'login' }); }, loginAction : function() { ...

Localized Error: The property 'clientWidth' cannot be retrieved as the object is null or undefined

The issue with the error message seems to only occur on Internet Explorer, and unfortunately there doesn't seem to be a clear solution at the moment. Even after setting http-equiv="X-UA-Compatible" to IE8, the problem persists and I cannot seem to re ...

Tips for creating an onClick event for a React Component that is passed as a prop to another component

I am currently in the process of creating a custom trigger component that can be passed down to another component. My goal is to implement a click event on this trigger component from the receiving component. If you'd like to see a live example, chec ...

Javascript and the output of Ajax request

I'm facing an issue with my JavaScript files interacting with the response from an ajax request. It seems that the JavaScript is unable to read the response from the ajax call. My question is, how can I get my jQuery plugin to access the classes in t ...

Can the server-side manipulate the browser's address bar?

Picture this scenario: a public display showcasing a browser viewing a web page. Can you send a GET or POST request from a mobile device to an HTTP server, causing an AJAX/pubsub/websocket JavaScript function to alter the displayed page on the screen? Per ...

Using Passport.js with a custom callback function that accepts parameters

I currently have this block of code: app.post('/login', passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }), function(req, res) { return res.redirect('/profile/&a ...

Why is my code throwing an error stating "Unable to assign value to innerHTML property of null"?

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>JS Bin</title> </head> <body> <div class="container">Lorem ipsum</div&g ...

Display information from a mysql database table within a selection menu

Currently, I am working on a dropdown menu that should display data from a MySQL table. However, I am facing an issue which is outlined below: In my PHP script, I have approached it in the following manner: <label class="col-form-label" for="formGrou ...

Unable to retrieve a response, the operation `users.findOne()` has exceeded the buffering time limit of 10000ms

I encountered an issue when attempting to make a POST login request. The frontend is deployed on Netlify here, and the backend is deployed on Heroku here. Here are my backend logs . I am receiving `users.findOne()` buffering timed out after 10000ms in ...

Animate a nested element dynamically with jQuery

Whenever I click on the "view" button, I am dynamically adding data to a div. This feature is working perfectly fine. However, I wanted to improve it by adding another nested dynamic element. The problem I'm facing now is that when I try to expand al ...

`Can a creation of this nature be accomplished?`

In my text input field, users can type messages to send to me. I'd like to add buttons on the page with symbols like "!", "XD", and "#". When someone clicks on a button, such as the "!" button, that corresponding symbol should be inserted into the tex ...

Verify in JavaScript if the script is executing within a WinStore (WinJS) program

I am in the process of developing a JavaScript library that is compatible with both Windows Store (WinJS) applications and traditional HTML/JavaScript apps. The dependency I am utilizing loads dynamically and has separate SDKs for WinJS apps and standard w ...

What is the role of the "prepare" function in AWS CDK constructs?

TL;DR: What is the role and purpose of the prepare(): void method in AWS CDK's Construct class? When and how should it be utilized or avoided? The information provided about prepare() states: prepare() function is called after child constructs have ...

Tips for accessing payment details from a stripe paymentElement component in a React application

Here is a basic code snippet for setting up recurring payments in Stripe: await stripe ?.confirmSetup({ elements, confirmParams: { return_url: url, }, }) After browsing through the documentation and the internet, I have two unanswere ...

Save the current time and date to a database by executing a mysql_query

<form action="actionMAppointment.php?stu_id=<?php echo $row_RecEdit['stu_id'] ?>" method="post"> Time: <input type = "time" name="appointmentTime" id = "appointmentTime" /> Date: <input type = ...

What is the method for accessing the value of variable "a" in the following code?

request(target, function (err, resp, body) { $ = cheerio.load(body); links = $('a'); $(links).each(function (i, link) { if ($(link).text().match('worker')) { var a = $(link).attr('href').toStri ...

Unleashing the power of jQuery, utilizing .getJSON and escaping

When I use .getJSON, the response I get is a JSON string with many \" characters. However, the callback function does not fire when the page is launched in Chrome. I have read that this happens because the JSON string is not validated as JSON (even th ...