snowflakedb / snowflake-connector-nodejs

NodeJS driver
Apache License 2.0
121 stars 130 forks source link

SNOW-1293653: ESM (ESModule) support #813

Open cjnoname opened 7 months ago

cjnoname commented 7 months ago

What is the current behavior?

This package does not support ESM (ESModule)

What is the desired behavior?

This package should suport both CommonJS and ESModule

How would this improve snowflake-connector-nodejs?

More and more new projects are adopting ESM

sfc-gh-dszmolka commented 7 months ago

thank you for submitting this enhancement idea - team will consider it for later, as it is not in the plans for the near future.

cjnoname commented 6 months ago

thank you for submitting this enhancement idea - team will consider it for later, as it is not in the plans for the near future.

Thanks dude!

bienzaaron commented 4 months ago

Would you accept a PR for this?

sfc-gh-dszmolka commented 4 months ago

as it is not in plans for the foreseeable future, if you however have the resources then it's indeed very much appreciated !

maxtuzz commented 3 months ago

Since most modern JS/TS codebases leverage ES Modules, could you at least provide documentation on how to update build config using commonjs/polyfill to be compatible?

EDIT: For those of you struggling to get this lib building and running in an ES Module based project. I'd recommend checking out Sequelize with their Snowflake experimental support. It uses this lib under the hood but provides good quality of life features on top of it such as using ESModule out of the box, it enables the use of async/await so you don't have to manage promise wrapping yourself (longest running feature request since 2018 on this lib) + you get the added benefit of adding types to your query results which is useful in Typescript based projects.

phdesign commented 2 days ago

Adding this shim to my esbuild options allows it work with ES Modules, but it's painful.

"banner": {
  "js": "import { createRequire } from 'module'; const require = createRequire(import.meta.url); import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); import path from 'path'; const __dirname = path.dirname(__filename);"
}