Node-oracledb: AngularJS & NodeJS & OracleDB Implementation Has Problem With The Library

Created on 3 Aug 2018  路  4Comments  路  Source: oracle/node-oracledb

For general questions:

I'm working on a project which uses AngularJS as fronted and NodeJS as backend. When I implement the .js folder that connects my oracle database server, the compiler gives me the error below.

Also the script works by itself via this command node app.js

How can I fix that?

Answer the following questions:

  1. What is your Node.js version? Is it 64-bit or 32-bit?

    64-bit & v8.11.8

  2. What is your node-oracledb version?

    v2.3.0

  3. What is your Oracle client (e.g. Instant Client) version? Is it 64-bit or 32-bit? How was it installed? Where is it installed?

    64-bit & v12.2

  4. What is your Oracle Database version?

    Up to date

  5. What is your OS and version?

    Windows 10@Latest

  6. What is your compiler version?
    >

  7. What Oracle environment variables did you set? How exactly did you set them?
    >

  8. What is the PATH environment variable (on Windows) or LD_LIBRARY_PATH (on Linux) set to? On macOS, what is in ~/lib?

    All have been set up as in the installation files.

  9. What exact command caused the problem (e.g. what command did you try to install with)? Who were you logged in as?

    const oracledb = require ('oracledb');

  10. What error(s) you are seeing?

    WARNING in ./node_modules/oracledb/lib/oracledb.js
    42:18-44 Critical dependency: the request of a dependency is an expression

    WARNING in ./node_modules/oracledb/lib/oracledb.js
    48:21-45 Critical dependency: the request of a dependency is an expression

    ERROR in ./node_modules/oracledb/lib/oracledb.js
    Module not found: Error: Can't resolve 'path' in 'C:\Users\tbyor\Desktop\angularProject\Base\node_modules\oracledb\lib'
    ERROR in ./node_modules/oracledb/lib/lob.js
    Module not found: Error: Can't resolve 'stream' in 'C:\Users\tbyor\Desktop\angularProject\Base\node_modules\oracledb\lib'
    ERROR in ./node_modules/oracledb/lib/querystream.js
    Module not found: Error: Can't resolve 'stream' in 'C:\Users\tbyor\Desktop\angularProject\Base\node_modules\oracledb\lib'

question

Most helpful comment

@tbyoran

Allow me to explain in a better manner. The problem is not your code, but how your project is built.

Angular is only meant for FrontEnd Development, you cannot have oracleDB inside an Angular project, it will not work properly. The angular code executes itself in the user's browser, which is completely different in nature to how OracleDB works. OracleDB compiles itself into a host machine, with proper adjustments made to behave correctly given different system/architecture etc. Thus, using OracleDB in a FrontEnd project is not a proper approach.

Your code for OracleDB functionality is correct, however, you need to separate it into a project of its own.

The correct way to design an application to access OracleDB is to have a backend only project that will access your data, and share that through Rest Apis. In your code screenshots, it is possible to see that the code is inside the Angular project, which is not the correct way to go. Start a new NPM project with only OracleDB and the dependencies needed to share data (express, koa, nest.js, pick your favorite). It will work for sure.

There are some other issues in this repo that have addressed the same question: https://github.com/oracle/node-oracledb/issues/894

I hope this clarifies your doubts.

All 4 comments

Angular code and oracledb don't go well together. (Angular executes client side...oracledb...doesn't)
By the looks of it you have it all bundled in a single project.
Consider using a rest-api project to provide you the data you need.
Here's a good place to start : https://jsao.io/2018/03/creating-a-rest-api-database-basics/

I use the same implementation for oracledb.

const oracledb = require ('oracledb'); This part gives me the error

const oracledb = require ('oracledb');
const config = require ('./dbconfig');

//...
constructor () {
    //console.log ("oracledb: " + oracledb);
    oracledb.getConnection (
      // Database Connection
      {
        user: config.user,
        password: config.password,
        connectString: config.connectString
      },
      function (err, connection) {
        if (err) {
          console.error ("Error #01: " + err.message);
          return;
        }
        this.conn = connection;
        console.log ("Connection is successful!");
      }
    );
}
//...

@tbyoran

Allow me to explain in a better manner. The problem is not your code, but how your project is built.

Angular is only meant for FrontEnd Development, you cannot have oracleDB inside an Angular project, it will not work properly. The angular code executes itself in the user's browser, which is completely different in nature to how OracleDB works. OracleDB compiles itself into a host machine, with proper adjustments made to behave correctly given different system/architecture etc. Thus, using OracleDB in a FrontEnd project is not a proper approach.

Your code for OracleDB functionality is correct, however, you need to separate it into a project of its own.

The correct way to design an application to access OracleDB is to have a backend only project that will access your data, and share that through Rest Apis. In your code screenshots, it is possible to see that the code is inside the Angular project, which is not the correct way to go. Start a new NPM project with only OracleDB and the dependencies needed to share data (express, koa, nest.js, pick your favorite). It will work for sure.

There are some other issues in this repo that have addressed the same question: https://github.com/oracle/node-oracledb/issues/894

I hope this clarifies your doubts.

Closing due to lack of activity. Thanks @danilohgds for your inputs.

Was this page helpful?
0 / 5 - 0 ratings