Problems encountered while building TypeScript on Azure's Hosted Agent

I'm currently working on an ASP.NET MVC application built in .Net5 that utilizes TypeScript files and includes NuGet package references for the following:

<PackageReference Include="BuildBundlerMinifier" Version="3.2.449" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.0.3">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.113" />

Within my project structure, I have:

  • A folder named node-modules (not pushed to Azure Devops)
  • bundleconfig.json
  • gulpfile.js
  • libman.json
  • package.json (+ package-lock.json)

The contents of my package.json are as follows:

{
  "version": "1.0.0",
  "name": "asp.net",
  "private": true,
  "devDependencies": {
    "gulp": "4.0.2",
    "del": "5.1.0",
    "@types/bootstrap": "4.5.0",
    "@types/google.visualization": "0.0.53",
    "@types/jquery": "3.5.1",
    "@types/jqueryui": "1.12.13",
    "@types/jquery.datatables": "1.10.36",
    "@types/jquery.ui.datetimepicker": "0.3.29"
  }
}

While compiling in Visual Studio 2019, everything functions correctly but I encountered a warning in the Build Output:

Package restore on project open is disabled. Change the npm package management settings in Project Properties to enable restore on project open.

To resolve this, I set "Restore On Project Save" to true, which added the following snippet to my csproj file:

<ProjectExtensions><VisualStudio><UserProperties appsettings_1qaf_1json__JsonSchema="https://gitpod.io/schemas/gitpod-schema.json" NpmRestoreOnProjectOpen="True" /></VisualStudio></ProjectExtensions>

After pushing the changes to Azure DevOps, I encountered errors when building with the hosted agent:

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:

- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'select'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    clean: true

This resulted in the error message:

##[error]MyApp\Scripts\MyTypeScript.ts(13,9): Error TS2581: Build:Cannot find name '$'. Do you need to install type definitions for jQuery? Try npm i @types/jquery.

It appears that the hosted agent is not retrieving the necessary types. I suspect adjustments are needed in my YAML file, but I am unsure of the correct approach...

Answer №1

Upon reviewing the error message and the Yaml definition, it appears that there is a missing step for NPM Install in order to install necessary npm packages.

The VSBuild task itself is only capable of restoring nuget packages and cannot handle the installation of npm packages. Therefore, additional tasks need to be added to facilitate the installation of npm packages.

One potential solution is to incorporate a Npm Install task prior to the execution of the VSBuild task.

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:

- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'select'

- task: Npm@1
  displayName: 'npm install'
  inputs:
    workingDir: '$(build.sourcesdirectory)'
    verbose: false


- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    clean: true

Result:

This approach should resolve the issue effectively.

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

The comet crash application is experiencing technical difficulties on Ubuntu version 14.01

jayesh@jayesh-VirtualBox:~/meteroapp/leadengine$ sudo npm install -g meteorite [sudo] password for jayesh: npm http GET https://registry.npmjs.org/meteorite npm http 304 https://registry.npmjs.org/meteorite npm http GET https://registry. ...

Using the function goToPage() within the TabbedHeaderPager component

I am currently working on a project that involves using TabbedHeaderPager, and I need to change tabs programmatically. I have been attempting to use the function goToPage() but have run into difficulties accessing it. I have tried passing it as a prop an ...

Refreshing the Mat Dialog content when removing items in Angular Material

I have successfully implemented a mat dialog table with 3 columns - name, email, and delete icon. When the user clicks on the delete icon, it prompts a confirmation message to confirm the deletion. Upon confirming, the item is removed from the database. Ho ...

Having trouble running the npm script due to a multitude of errors popping up

I have encountered an issue while trying to run an npm script. I added the script in the `package.json` file multiple times, but it keeps showing errors. I am currently working on building a website and require npm sass for it. However, when I try to run t ...

Error in Typescript: Function expects two different types as parameters, but one of the types does not have the specified property

There's a function in my code that accepts two types as parameters. handleDragging(e: CustomEvent<SelectionHandleDragEventType | GridHandleDragEventType>) { e.stopPropagation(); const newValue = this.computeValuesFromPosition(e.detail.x ...

Explanation of TypeScript typings for JavaScript libraries API

Currently, I am in the process of building an Express.js application using TypeScript. By installing @types and referring to various resources, I managed to create a functional program. However, my main query revolves around locating comprehensive document ...

Leveraging string interpolation in Typescript with a string sourced from a file

After diving into Typescript, I came across some intriguing information on template strings. One question that popped into my mind is whether these template strings can be utilized when reading a string from a file, just like this: let xmlPayloadTemplate ...

The npm installation encounters an error when trying to connect to the incorrect host, causing

I can't seem to complete the npm install process: λ npm install -g pageres-cli npm ERR! code ETIMEDOUT npm ERR! errno ETIMEDOUT npm ERR! network request to http://calculon:4873/pageres-cli failed, reason: connect ETIMEDOUT 192.168.10.99:4873 The nam ...

Step-by-step guide on utilizing the vendor.ts file available at https://angular.io/docs/ts/latest/guide/webpack.html

As per the guidelines provided at https://angular.io/docs/ts/latest/guide/webpack.html, it is recommended to include vendors like jQuery in the vendor.ts file. // Other vendors for instance jQuery, Lodash or Bootstrap // You can import js, ts, css, sass, ...

Learn the technique for dynamically modifying Angular components within the main root component during runtime

I am looking to incorporate a dynamic form where the configuration button triggers the switch from app-login-form to login-config-form. app.component.html <div class="container p-5"> <app-login-header></app-login-header> <div cla ...

The different versions of NPM utilized throughout the software development and production process

Based on my understanding, it is advisable to maintain the same version of Node.js consistently from development to production stages of an application. But what about NPM? It seems like NVM keeps specific versions of NPM along with corresponding Node.js ...

What is the process for installing Node Js on xfce/ Debian based linux distributions?

I'm looking for guidance on installing Node Js and npm in Xfce/Debian based Linux distros. Any assistance would be greatly appreciated. ...

Not suitable for Heroku deployment

I have been attempting to deploy this Nuxt.js application on Heroku in universal mode. Following the necessary steps like "npm run build" and "npm run start" for production mode, everything seemed to be working smoothly. Next, I executed the following co ...

The integrity verification for "anymatch" has not passed (the calculated integrity does not align with our records, received)

In my node.js project (specifically Nest JS), I am facing an issue where I need to reinstall a dependency after encountering the same error mentioned below. This situation is new to me. Upon checking the yarn.lock and package.json files, I noticed that th ...

Designing a user interface for unlimited nested components with optional properties

I am currently working on creating an interface for the specific object type shown below. "Condition": { "And": { "Or": { "userData": [ { "name": "Alex", &q ...

Mapping two objects of the same shape to each other recursively using TypeScript

I receive regular data from a specific source. This data consists of nested objects containing numerical values. For example: { a: 1, b: { c: 2, d: 3.1, }, } My objective is to organize this data into multiple TimeSeries objects of the same struct ...

Unpacking JSON Objects in Typescript: Working with Private Variables

I have a TypeScript model object called user export class User { constructor( private _name: string, private _email: string ) {} public get name():string { return this._name; } public set name(value:string) { this._name = value; } g ...

There seems to be a problem fetching the WordPress menus in TypeScript with React and Next

Recently I've started working on a project using React with TypeScript, but seems like I'm making some mistake. When trying to type the code, I encounter the error message: "TypeError: Cannot read property 'map' of undefined". import Re ...

Limiting the assignment of type solely based on its own type, without considering the components of the type

I have defined two distinct types: type FooId = string type BarId = string These types are used to indicate the specific type of string expected in various scenarios. Despite TypeScript's flexibility, it is still possible to perform these assignment ...

Error message "MODULE_NOT_FOUND" appears when using Next.js and React together

Hello everyone, I am encountering an issue with my app when running the "npm run dev" command. I keep seeing the "MODULE_NOT_FOUND" error. Can someone please assist me in resolving this? My current node version is "v20.6.1" and npm version is "10.2.5" Co ...