cloudant / nodejs-cloudant

Cloudant Node.js client library
Apache License 2.0
255 stars 90 forks source link

multiple "Module not found: ERROR: Can't resolve '...'" after ionic serve #368

Closed mensch72 closed 5 years ago

mensch72 commented 5 years ago

Bug Description

1. Steps to reproduce and the simplest code sample possible to demonstrate the issue

E.g.,

2. What you expected to happen

The app should compile and show up in the browser.

3. What actually happened

App does not compile, with error as follows:

[ng] ERROR in ./node_modules/lockfile/lockfile.js
[ng] Module not found: Error: Can't resolve 'constants' in 'XXX/node_modules/lockfile'
[ng] ERROR in ./node_modules/aws-sign2/index.js
[ng] Module not found: Error: Can't resolve 'crypto' in 'XXX/node_modules/aws-sign2'
[ng] ERROR in ./node_modules/aws4/aws4.js
[ng] Module not found: Error: Can't resolve 'crypto' in 'XXX/node_modules/aws4'
[ng] ERROR in ./node_modules/ecc-jsbn/index.js
[ng] Module not found: Error: Can't resolve 'crypto' in 'XXX/node_modules/ecc-jsbn'
[ng] ERROR in ./node_modules/http-signature/lib/signer.js

and so on.

Environment details

I'm using node 10.15.1, npm 6.8.0, @ionic/angular@4.0.1, @ionic/core@4.0.1 on Ubuntu 18.04

glynnbird commented 5 years ago

Instead of doing:

declare var require: any;
require('@cloudant/cloudant');

try

import * as Cloudant from '@cloudant/cloudant'

I think the declare var require: any; statement is killing the require function. See https://www.typescriptlang.org/docs/handbook/modules.html

I don't think isn't a nodejs-cloudant issue, just a problem with your TypeScript code.

mensch72 commented 5 years ago

When doing this, the import works, but as soon as I try using the API, I still get the same error. My src/app/app.component.ts now looks like this:

import * as Cloudant from '@cloudant/cloudant'

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

import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html'
})
export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar
  ) {
    this.initializeApp();
    let cloudant_username = "some valid username",
        cloudant_password = "some value password";
    let cloudant = Cloudant({ account:cloudant_username, password:cloudant_password });
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }
}
mensch72 commented 5 years ago

I suspect the issue must be related to nano, since if I try requiring either nano or cloudant-nano instead of @cloudant/cloudant, I get the same kind of error.

smithsz commented 5 years ago

Hello - I've been able to reproduce this problem. The errors I'm seeing are similar to https://github.com/ionic-team/ionic/issues/4986. The issue comments suggest that including third party libraries works only for selected modules.

Unfortunately we don't provide support for using nodejs-cloudant as part of an ionic project. If you manage to resolve the problem please update this issue with your fix.

Thanks.