浏览器中的 Node-oracledb 错误 "Module name has not been loaded for context yet"

Node-oracledb in browser error "Module name has not been loaded for context yet"

我正在尝试使用 node-oracledb 从 oracle 数据库加载数据,但我收到此错误:

Error: Module name "select1" has not been loaded yet for context: _. Use require([])

我确实阅读了文档 here,但我想不出解决方案。为什么会给我这样的错误,为什么要感谢您的帮助。

select1.js :

   const oracledb = require('oracledb');
   const dbConfig = require('./dbconfig.js');
   const demoSetup = require('./demosetup.js');
   oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
   async function run() {
   let connection;

   try {
   // Get a non-pooled connection

  connection = await oracledb.getConnection(dbConfig);

  await demoSetup.setupBf(connection);  // create the demo table

  var query = await connection.execute(
    // The statement to execute
    `SELECT * From pilote`,

    // The "bind value" 3 for the bind variable ":idbv"
    [],

    // Options argument.  Since the query only returns one
    // row, we can optimize memory usage by reducing the default
    // maxRows value.  For the complete list of other options see
    // the documentation.
    {
      maxRows: 100
      //, outFormat: oracledb.OUT_FORMAT_OBJECT  // query result format
      //, extendedMetaData: true                 // get extra metadata
      //, fetchArraySize: 100                    // internal buffer allocation size for tuning
    });
    //console.log(query.rows)

} catch (err) {
  console.error(err);
} finally {
  if (connection) {
    try {
      // Connections should always be released when not needed
      //await connection.close();
    } catch (err) {
      console.error(err);
    }
  }
}
return query;
}
module.exports.run =  run;

test.js :

(async() =>{
var result = require('./select1').run()
var rs;
rs = (await result).rows
if(rs !== undefined)
{
    document.getElementById('hdr').textContent = rs[0]
}
})()

page.html :

<body>
<h1 id="hdr">hello</h1>
<script src="https://requirejs.org/docs/release/2.3.5/minified/require.js"></script>
<script  src="test.js"></script>
</body>

node-oracledb 不会在浏览器中 运行 因为它有一个需要访问二进制共享库的二进制组件。标准 Node.js 应用程序设计具有 Node.js 作为接受网络调用的中间层应用程序服务器,例如REST,从浏览器和 returns 数据到该浏览器。有一些用法变体,例如作为使用 Electron 的独立应用程序。

如果这对您来说是全新的,请从示例开始 https://github.com/oracle/node-oracledb/blob/master/examples/webappawait.js and work up to https://jsao.io/2018/03/creating-a-rest-api-with-node-js-and-oracle-database/