Module not found: Error: Can't resolve 'http'. Unable to serve Angular6 application with Jenkins Module

1,289 views
Skip to first unread message

Renjith R

unread,
Sep 10, 2018, 1:20:33 AM9/10/18
to Angular and AngularJS discussion

I am novice in Angular 6 (more appropriately Angular > 1). I am basically trying to pull some data from Jenkins and present in on an Angular backed UI application.

At first, I followed the below tutorial to start with. https://programmingwithmosh.com/angular/angular-4-tutorial/

I ensured that I am able to access the "http://localhost:4200" after performing "ng serve".

To access Jenkins, I used Jenkins module from NPM. https://www.npmjs.com/package/jenkins

Installed the same using npm install jenkins

Then modified the app.component.ts with the following code to pull information from Jenkins.


import { Component, OnInit } from '@angular/core';

declare var require: any;

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{
  title = 'Study1Jenkins';

  ngOnInit() {

    var jenkins = require('jenkins')({ baseUrl: 'https://UN:P...@myjenkins.com', crumbIssuer: true });

    jenkins.info(function(err, data) {
      if (err) throw err;

      console.log('info', data);
    });

  }

}


Then I tried to do an ng serve which resulted in the following error.


ERROR in ./node_modules/papi/lib/client.js Module not found: Error: Can't resolve 'http' in '\Study1Jenkins\node_modules\papi\lib' ERROR in ./node_modules/papi/lib/client.js Module not found: Error: Can't resolve 'https' in '\Study1Jenkins\node_modules\papi\lib' i wdm」: Failed to compile.

If somebody can give a hint on what has gone wrong, that will be really helpful.

Sander Elias

unread,
Sep 10, 2018, 1:38:33 AM9/10/18
to Angular and AngularJS discussion
Hi Renjith,

Ok, first of all, this is just a hunch. As I have no experience with what you are trying to do. 
However, looking at the error, and your code I made the assumption that you are trying to do the following thing:

Load Jenkins after your app has started, dynamically in the browser. 
However, typescript sees the require statement and tries to load it during compile time.  Change your code so it doesn't depend on require.

Regards
Sander

Sander Elias

unread,
Sep 10, 2018, 1:41:23 AM9/10/18
to Angular and AngularJS discussion
Also, (I just checked what your npm-module does ;) ) the Jenkins module is built for server-side(nodeJS) usage, and will probably not work in a browser anyway.

Renjith R

unread,
Sep 10, 2018, 2:50:02 AM9/10/18
to ang...@googlegroups.com
Not exactly,  Sander. It is a Jenkins API, that can be used to access Jenkins which is already running and to pull information from that. Say for eg, if I need to know how many jobs are currently running, build a specific job programmatically, get the latest build info of a job etc..
Hope you get it. Let me know if you need more info. 

On Mon, Sep 10, 2018, 11:11 Sander Elias <sande...@gmail.com> wrote:
Also, (I just checked what your npm-module does ;) ) the Jenkins module is built for server-side(nodeJS) usage, and will probably not work in a browser anyway.

--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Sander Elias

unread,
Sep 10, 2018, 2:56:46 AM9/10/18
to Angular and AngularJS discussion
Reply all
Reply to author
Forward
0 new messages