Ways to resolve a TypeScript reference error when working with Google Cloud Build

In my typescript monorepo, a vue 3 app is importing custom types and config constants from modules/packages specifically created for the app, such as @myapp/types or @myapp/config. These packages are private and not pulled from the npm registry. Locally, I have no issues with importing, building, or running the app. However, during Cloud Build, my builds consistently fail with the following error message:

https://i.sstatic.net/KTYOV.png

Below are the tsconfig.json files used in the "importer" repository, which is my Vue app utilizing the types and going through the pipeline:

tsconfig.json:

{
  "files": [],
  "compilerOptions": {
    "forceConsistentCasingInFileNames": true,
    "strict": true
  },
  "references": [
    {
      "path": "./tsconfig.vite-config.json"
    },
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.vitest.json"
    },
    {
      "path": "../../packages/types/tsconfig.json"
    },
    {
      "path": "../../packages/config/tsconfig.json"
    }
  ]
}

tsconfig.app.json:


{
  "extends": "@vue/tsconfig/tsconfig.web.json",
  "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
  "exclude": ["src/**/__tests__/*"],
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "composite": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"],
      "@myapp/config": ["../../packages/config"],
      "@myapp/types": ["../../packages/types"]
    }
  }
}

The structure of the monorepo looks like this:

  • root (tsconfig.base.json)
    • apps
      • ui <== consumer (tsconfig.app.json + tsconfig.json)
    • packages
      • types <= custom types (tsconfig.json)
      • config <= custom types

Just to add information, here's the tsconfig.json present in the types module:

{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": {
    "target": "ESNext",
    "module": "ES6",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "moduleResolution": "Node",
    "allowSyntheticDefaultImports": true,
    "emitDeclarationOnly": true
  },
  "files": ["index.ts"],
  "display": "Types"
}


Moreover, here's the tsconfig.base.json situated at the root of the repo:

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "baseUrl": ".",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "composite": true,
    "declaration": true,
    "declarationMap": true,
    "paths": {
      "@myapp/types": ["./packages/types"],
      "@myapp/config": ["./packages/config"],
      "@myapp/ui": ["./packages/ui"],
      "@myapp/ui-b2b": ["./apps/ui-b2b/src"],
      "@myapp/ui-partners": ["./apps/ui-patners/src"],
      "@myapp/api": ["./apps/api/src"]
    }
  }
}

Lastly, here's the content of my cloudbuild yaml file:

steps:
  - name: node:16
    entrypoint: npm
    args: ["install"]
  - name: node:16
    dir: "apps/ui-b2b"
    entrypoint: npm
    env:
      - "DEPLOYMENT_TARGET=$_DEPLOYMENT_TARGET"
      - "VITE_RECAPTCHA_SITE_KEY=$_VITE_RECAPTCHA_SITE_KEY"
      - "VITE_DYNAMIC_LINKS_DOMAIN=$_VITE_DYNAMIC_LINKS_DOMAIN"
      - "VITE_API_URL=$_VITE_API_URL"
      - "VITE_DISPOSABLE_API_KEY=$_VITE_DISPOSABLE_API_KEY"
      - "VITE_GCP_AUTH_TENANT_ID=$_VITE_GCP_AUTH_TENANT_ID"
      - "VITE_FIREBASE_CONFIG=$_VITE_FIREBASE_CONFIG"
      - "VITE_BASE_DOMAIN=$_VITE_BASE_DOMAIN"
      - "VITE_LOCAL=$_VITE_LOCAL"
      - "VITE_STRIPE_ALLOW_PROMOTION_CODES=$_VITE_STRIPE_ALLOW_PROMOTION_CODES"
      - "VITE_TOAST_DURATION=$_VITE_TOAST_DURATION"
      - "VITE_SEARCH_API_KEY=$_VITE_SEARCH_API_KEY"
      - "VITE_SEARCH_API_HOST=$_VITE_SEARCH_API_HOST"
      - "VITE_SEARCH_API_PORT=$_VITE_SEARCH_API_PORT"
      - "VITE_SEARCH_API_PROTOCOL=$_VITE_SEARCH_API_PROTOCOL"
    args: ["run", "build:development"]
  - name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
    entrypoint: "bash"
    dir: "apps/ui-b2b"
    args:
      [
        "-c",
        "gcloud config set app/cloud_build_timeout 1600 && gcloud app deploy",
      ]
timeout: "1600s"

I've attempted various solutions like adjusting paths and removing references, but each time it results in different errors. Any insights on why this might be happening or how it can be resolved would be greatly appreciated.

Thank you in advance,

Answer №1

It turns out the error in typescript was like a single tree blocking the view of the entire forest. Although I still don't fully understand why this issue occurred, here's an overview of what happened.

During deployment to Google App Engine using the gcloud app deploy command, the platform attempts to build the application before deploying it by default. To address this, my deployment process consisted of the following steps:

  • step 1: npm i
  • step 2: npm build for development
  • step 3: deployment (with a default npm build triggered before deployment)

I suspect that during step 3, certain TypeScript modules or packages that the application relied on were removed from the pipeline since the app had already been built earlier.

To prevent this default behavior and ensure smooth builds and deployments, I disabled the automatic build execution on Google App Engine by including

"gcp-build": ""
in my package.json, as outlined in the documentation provided here:

https://cloud.google.com/appengine/docs/standard/nodejs/runtime#npm_build_script

https://i.sstatic.net/JlGiq.png

Following this adjustment, my builds and deployments proceeded without any further issues.

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

Tips for splitting JSON objects into individual arrays in React

I'm currently tackling a project that requires me to extract 2 JSON objects into separate arrays for use within the application. I want this process to be dynamic, as there may be varying numbers of objects inside the JSON array in the future - potent ...

Steps for submitting a form when the input value changes

I'm facing an issue with my form. I want a function to run every time the user changes a value in the input field, so I attached a small function to the form like this: onChange={() => { formRef.current?.submit(); }} However ...

Translate Firestore value updates into a TypeScript object

Here are the interfaces I'm working with: interface Item { data: string } interface Test { item: Item url: string } In Firestore, my data is stored in the following format: Collection Tests id: { item: { data: " ...

Error in nodejs typescript multer S3 upload - Cannot read map properties of undefined

I've created a route to upload files to an S3 bucket, and it's working perfectly. However, when I try to integrate it into my Accommodation controller with additional logic, I'm getting the error Cannot read properties of undefined (reading ...

Creating a Class in REACT

Hello fellow coding enthusiasts, I am facing a minor issue. I am relatively new to REACT and Typescript, which is why I need some assistance with the following code implementation. I require the code to be transformed into a class for reusability purposes ...

The peculiar type intersection of 'string & {}'

There is a TypeScript syntax often seen in some libraries like this: type AriaRole = 'alert' | 'tree' | 'treegrid' | 'treeitem' | (string & {}); Can someone explain the meaning of string & {}? It represent ...

Challenges arise when using scoped styles and deep styling in the context of Vue 3

Struggling with styling a child component from its parent in vue3 and encountering difficulties. In this scenario, I have created a generic button with predefined CSS properties and now attempting to customize this button from another component. Parent C ...

How can I create interfaces for deeply nested objects in TypeScript?

Check out my current JSON data below: { "state_1": { "date": [ { 1000: { "size": 3, "count": 0 } }, { 1001: { "size" ...

How to format decimals in Typescript/Angular with a pipe: comma or dot?

I've recently developed a custom pipe and I'm looking to enhance it by adding commas or periods to thousands values. For instance, 1000 should be displayed as either 1,000 or 1.000. Here is the code snippet for my custom pipe: import { Pipe, Pi ...

Controlling the upper and lower limits in an input field for numerical values while manually typing in the text

Trying to implement an Angular component input with number type that allows setting a maximum and minimum value. Here is the code snippet used for calling the component in HTML: <app-input-number [(value)]="inputMinMaxValueNumber" [min]="min" [max]="m ...

Error encountered when using the refresh token API: "Value required for secretOrPrivateKey"

Upon user login to the API, a token is generated for access to other endpoints. However, this token expires within 60 seconds. I have implemented a function to generate a new valid token using the old token stored in the database. Yet, when attempting to c ...

How can I redirect a page using an axios interceptor in Next.js?

Is there a way to redirect the page in an axios interceptor when dealing with server-side rendering limitations? Unfortunately, I am unable to access the server side context in the axios interceptor. I have tried using next/router but it only works on the ...

No defined outcome when using a conditional input with a name attribute

I am facing an issue while trying to determine whether to show/hide mybutton. The console keeps throwing an error stating that mybutton is undefined whenever it tries to evaluate mybutton.disabled. To troubleshoot, I included a true statement: 1===1, but ...

Filtering an array in Angular, but excluding the initial element from the filter process

I am currently dealing with an array of objects that I need to filter. My issue is that I do not want the first element in the array to be removed during the filtering process. Here is an example of how the array (oData) might be structured: [ {id: " ...

In the production build, the RegEx validation is lacking and fails to accept certain characters like 0, 2, 7, a, c, u, x, and occasionally z

Incorporating Angular 15.2.10 and Typescript 4.9.5, the RegEx utilized in one of my libraries and exposed via a service is outlined as follows: private readonly _DISALLOWED_CHARS_REGEX_GENERAL = new RegExp(/^[^\\/\?\!\&\: ...

Angular's observable data fail to show on the screen

I am facing an issue with passing the data of an Observable fetched via an API request to a component variable for display. I have been trying but unable to make it work successfully. Any assistance would be greatly appreciated. Here is my code. Thank you. ...

SQLite - executing multiple calls within a single transaction

Greetings, I am currently working on developing a front end Single Page Application (SPA) using Typescript. I have chosen to utilize capacitorJS for cross-platform compatibility and have integrated the @capacitor-community/sqlite plugin into my project. Wh ...

A windows application developed using either Javascript or Typescript

Can you provide some suggestions for developing Windows applications using Javascript, Typescript, and Node.js? ...

What is the process for extracting the background color from a typescript file in Angular and connecting it to my HTML document?

My typescript array population is not changing the background color of my div based on the values in the array. I've attempted to set the background using [style.backgroundColor]="statusColor[i]", where statusColor is an array declared in my typescrip ...

Challenges in integrating a PrimeNG Angular2 component with DynamicDialogRef, as well as the difficulties encountered when attempting to do

I am currently working on implementing a component that utilizes dynamic dialog and requires a direct usage. In the DynamicDialog example, there is a constructor in the car demo list component. constructor(private carService: CarService, public ref: Dynami ...