You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2021/04/16 13:54:37 UTC

[GitHub] [couchdb-nano] davidgeary opened a new issue #265: Unable to resolve modules when used in Angular project

davidgeary opened a new issue #265:
URL: https://github.com/apache/couchdb-nano/issues/265


   ## Expected Behavior
   I expect the project to build without errors.
   
   ## Current Behavior
   I'm writing an Angular project to which I've added nano (as per <https://github.com/apache/couchdb-nano#typescript>).  But as soon as I include a call such as:
   
   ``` typescript
   let n = Nano('http://localhost:5984');
   ```
   
   I get errors when building the project about missing modules, eg:
   
   > Error: ./node_modules/nano/lib/nano.js
   > Module not found: Error: Can't resolve 'http' in 'C:\code\my-app\node_modules\nano\lib'
   
   (The actual error then lists all of the places it has checked for the existence of the missing module, which I'm omitting for brevity.)
   
   The same error message is repeated for the `https` and `stream` modules.
   
   ## Steps to Reproduce
   
   ### Stackblitz
   
   I've created a [sample of this on Stackblitz](https://stackblitz.com/edit/angular-with-nano?file=src%2Fapp%2Fapp.component.ts).  Stackblitz doesn't show the full underlying console error message unfortunately, but does show the message:
   
   > Can't find packages:
   > url http https events punycode
   
   ### Locally
   
   If you have the Angular CLI installed, this can be seen in a minimal sample:
   
   Create a new Angular app and then install nano:
   
   ``` sh
   ng new my-app --minimal=true --routing=false --skipGit=true --interactive=false
   cd my-app
   npm install nano
   ```
   
   Edit `tsconfig.json` to include `"allowSyntheticDefaultImports": true` under `compilerOptions`.
   
   Edit `app.component.ts` to:
   
   * import the nano library at the top of the file
   ``` typescript
   import * as Nano from 'nano';
   ```
   * add a function to call nano (we're only going to build the project, so it doesn't matter if the URL doesn't point to a valid CouchDB server):
   ``` typescript
     ngOnInit() {
       const connection = Nano('http://localhost:5984/');
     }
   ```
   
   Then build the project with `ng build`
   
   ## Your Environment
   * Version used: 9.0.3
   * Angular version: 11.2
   * Typescript version: 4.1.5
   * Browser Name and version: N/A
   * Operating System and version (desktop or mobile): Windows 10
   * Link to your project: <https://stackblitz.com/edit/angular-with-nano?file=src%2Fapp%2Fapp.component.ts>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb-nano] davidgeary commented on issue #265: Unable to resolve modules when used in Angular project

Posted by GitBox <gi...@apache.org>.
davidgeary commented on issue #265:
URL: https://github.com/apache/couchdb-nano/issues/265#issuecomment-919160724


   That makes sense - thanks @glynnbird.
   
   As it happens, I did end up writing directly against the CouchDB API (using Angular's `HttpClient` service), so yes, I've now learnt the API which is no bad thing.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb-nano] glynnbird commented on issue #265: Unable to resolve modules when used in Angular project

Posted by GitBox <gi...@apache.org>.
glynnbird commented on issue #265:
URL: https://github.com/apache/couchdb-nano/issues/265#issuecomment-918290603


   I think this is as a result of using Nano in a browser, rather than server-side from within a Node.js project. So the browser doesn't know what the `http`, `https` and `stream` modules are. 
   
   I'm no expert in transpiling Node.js modules for browser use.
   
   If I were writing to CouchDB from within the browser, I'd use [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) - not quite as easy as Nano, but definitely not unmanageable - and you get to learn the CouchDB API too! :)
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb-nano] davidgeary closed issue #265: Unable to resolve modules when used in Angular project

Posted by GitBox <gi...@apache.org>.
davidgeary closed issue #265:
URL: https://github.com/apache/couchdb-nano/issues/265


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org