Posted on Leave a comment

npm ERR! ERESOLVE could not resolve dependency

I was working on a project which had a node install task as a part of a docker file build. The build was not successful due to the error shown below. This is a dependency error and can be solved by choosing the right versions on your package-lock.json.

package-lock.json is automatically generated for any operations where npm modifies either the node_modules tree, or package.json. It describes the exact tree that was generated, such that subsequent installs are able to generate identical trees, regardless of intermediate dependency updates.

However there is also another way you can get rid of such cases. If you do have specific dependencies inside your package-lock.json you can proceed with the following steps.

Remove package-lock.json from your project
Remove node_modules folder 
Run npm install 
Posted on Leave a comment

Build NodeJS applications using Azure devops and npm

In this article I will explain how you can build your nodeJS application on Azure Devops. For the purposes of this demo I have created a hello world javascript application and stored it under a folder called node inside my repository with the name project.

We will use the folder structure later on for the build tasks.

The node folder contains two files, index.js and package.json. 

The package.json file has been created automatically after initialization of a new project with

npm init

In order to build this project using npm you should define under the scripts section the commands that will be executed using a specific target. 

For example in order to compile application I will execute

npm run build

but the build instructions have to be configured under the package.json file. 

{
"name": "nodetest",
"version": "1.0.0",
"description": "Test project for AzureDevops using nodeJS",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "node index.js",
"build": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.1"
}
}

As shown above, the build and dev targets have a simple node command that will start the application.

The index.js file is a console output javascript command.

console.log("Hello from node js app");

In order to build this node app using devops I will use the build in Npm@1 task. First I will execute the install command in order to install dependencies. Then I will run npm run with the target build. This will execute the node index.js command and will execute the node application.

trigger:
- none
pool:
vmImage: ubuntu-latest
steps:
- task: Npm@1
displayName: npm install
inputs:
command: 'install'
workingDir: '$(Build.SourcesDirectory)/node/'
- task: Npm@1
displayName: npm run build
inputs:
command: 'custom'
workingDir: '$(Build.SourcesDirectory)/node/'
customCommand: 'run build'

After pipeline run the Hello world message will print on the output.

Find this guide on Youtube:

Posted on Leave a comment

Error MSB3073 The command “npm run build” exited with code 1 – Visual Studio

Recently I was trying to build a complex project which included also node js code and was deployable to IIS. The error I faced on visual studio during the build was the below.

"npm run build" exited with code 1 - Visual Studio 
"npm install" exited with code 1 - Visual Studio

both of which were misleading.

In order to locate the error I navigated on the Node project and tried to build using

npm run build

Command line never lies. I was able to determine that webpack was not installed.

In order to resolve I executed:

npm install -g webpack
npm install -g webpack-cli