Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import postgres-js as an ESM module in node. #411

Open
tomprince opened this issue Mar 10, 2023 · 2 comments · May be fixed by #410
Open

Cannot import postgres-js as an ESM module in node. #411

tomprince opened this issue Mar 10, 2023 · 2 comments · May be fixed by #410
Labels
bug Something isn't working

Comments

@tomprince
Copy link

Bug report

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

  1. Create a new package and install postgres-js:
    mkdir test-package && cd test-package
    echo '{}' > package.json
    npm install @supabase/postgrest-js@latest
    
  2. Create a module that tries to import a named export from postgrest-js:
 echo 'import { PostgrestClient } from "@supabase/postgrest-js"'  > test.mjs
  1. Try to run the module with node:
    node test.mjs
    
4. Note the error trying to import a commonjs module.

## Expected behavior

I expect the above import to work and import an ESM module.

## Screenshots

❯ node test.mjs
file:///.../test.mjs:1
import { PostgrestClient } from "@supabase/postgrest-js"
^^^^^^^^^^^^^^^
SyntaxError: Named export 'PostgrestClient' not found. The requested module '@supabase/postgrest-js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@supabase/postgrest-js';
const { PostgrestClient } = pkg;

at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)

Node.js v19.6.0


## System information

- Version of supabase-js: 1.4.1
- Version of Node.js: v19.6.0

## Additional context

It appears that node only looks at the `main` entrypoint in `package.json`, and not `module`. It also specifies a newer and more complex way of specifying see [here](https://nodejs.org/api/packages.html#package-entry-points) for details.
@tomprince tomprince added the bug Something isn't working label Mar 10, 2023
@tomprince tomprince linked a pull request Mar 10, 2023 that will close this issue
@humphd
Copy link

humphd commented Mar 16, 2024

I'm hitting this over and over with postgrest-js trying to use it in different environments. To get my code to work, I have to use all 3 of these in different contexts:

// XXX: ncc wants
import * as postgrest from "@supabase/postgrest-js";

// XXX: esbuild wants:
import postgrest from "@supabase/postgrest-js";

// tsx wants:
import { PostgrestClient } from "@supabase/postgrest-js";

It would be great to be able to use this module without it breaking on import so much.

@humphd
Copy link

humphd commented Aug 31, 2024

Burned again by this in production tonight:

import { PostgrestClient } from '@supabase/postgrest-js';
         ^^^^^^^^^^^^^^^
SyntaxError: The requested module '@supabase/postgrest-js' does not provide an export named 'PostgrestClient`

Supabase ships so much amazing software. Could we get a fix for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants