Switch to new style imports.#410
Conversation
bbad37a to
f8d690f
Compare
| @@ -0,0 +1,3 @@ | |||
| import * as fs from 'fs' | |||
|
|
|||
| fs.writeFileSync('./dist/main/package.json', '{"type": "commonjs"}') | |||
There was a problem hiding this comment.
Node looks at type in the nearest package.json to tell if a .jsfile should be interpreted as an ESM or commonjs module. You can use .mjs or .cjs to specify this on a per-file basis, but typescript doesn't have any support for that. See https://github.com/azu/tsconfig-to-dual-package#motivation for more details and links to discussion about this.
I elected to put type: module in the top-level package, since my impression is that the ecosystem is slowly moving towards ESM style modules.
| testEnvironment: 'node', | ||
| moduleNameMapper: { | ||
| '^(\\.{1,2}/.*)\\.js$': '$1', | ||
| }, |
There was a problem hiding this comment.
I copied this from https://kulshekhar.github.io/ts-jest/docs/guides/esm-support, but it isn't clear to me why this isn't included in any of the presets.
f8d690f to
b7f863d
Compare
|
Hi @tomprince ! Thanks for the contribution and your patience. This repository is deprecated and has moved to the new Supabase JS monorepo. Since this PR has been inactive for over a year, I’m going to close it to keep the old repo tidy, before archiving. If you believe this change is still needed, please open a new PR in the monorepo and include a link back to this thread for context:
Note: This old repository will be archived on October 10, 2025. Thank you again for your effort and understanding! |
What kind of change does this PR introduce?
This adds support for importing postgrest-js as an ESM module in node.
What is the current behavior?
Currently, postgrest-js can only be imported as a CommonJS module on node (fixes #411).
Additional context
As written, this prevents imports like
require("@supabase/postgrest-js/dist/main/PostgrestBuilder.js"). Node's docs suggest that this is a breaking change:However, I think that is only true if you consider that kind of import to be part of your public interface. The documentation does suggest a way to continue to support that kind of import if desired.
Looking at the code, the only things that could be accessed that way that aren't available from the top-level import are in
src/types.tsandsrc/constants.ts.This seems to work when I test locally, but I don't know enough about how this package is used in the wild to know if this might cause issues for other consumers.