standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 147 forks source link

Cannot collaborate with oracledb library #881

Closed lsby closed 2 years ago

lsby commented 4 years ago

Preliminary operation

npm i oracledb oracledb: https://www.npmjs.com/package/oracledb

operating

code:

import oracledb from 'oracledb'
var oracledb2 = require('oracledb')

console.log(oracledb.getConnection == oracledb2.getConnection)

oracledb.getConnection({
    user: 'xxx',
    password: 'xxx',
    connectString: 'xxx/xxx',
}, (err, conn) => {
    console.log(err, conn)
})

error:

$ node -r esm index.js
true
C:\Users\hby\Desktop\test\node_modules\oracledb\lib\oracledb.js:1
Error: Invalid argument
    at Proxy.getConnection (C:\Users\hby\Desktop\test\node_modules\oracledb\lib\oracledb.js:287:10)
    at Proxy.<anonymous> (C:\Users\hby\Desktop\test\node_modules\oracledb\lib\util.js:185:19)
    at Object.<anonymous> (C:\Users\hby\Desktop\test\index.js:6:10)
    at Generator.next (<anonymous>)

But if I write:

// import oracledb from 'oracledb'
var oracledb2 = require('oracledb')

// console.log(oracledb.getConnection == oracledb2.getConnection)

oracledb2.getConnection({
    user: 'xxx',
    password: 'xxx',
    connectString: 'xxx/xxx',
}, (err, conn) => {
    console.log(err, conn)
})

run:

$ node index.js

it work

I think it has something to do with esm