-
Notifications
You must be signed in to change notification settings - Fork 129
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
Can't import the library in Node #5
Comments
Thanks for reporting the issue. The bundle issues were resolved in v0.1.2 release. To load for node.js environment, now it should be enough to do: const PocketBase = require("pocketbase"); OR if you are using es6 style imports (suitable also for the browser if you are using a bundler like rollup and webpack): import PocketBase from "pocketbase"; More details could be also found in the Installation readme section If you are still experiencing issues, please let me know and I'll try to investigate it further. |
I got import problem when using a simple typescript file running with ts-node. My project require using typescript with commonjs.
When running ts-node, It throws an error
Here's my tsconfig.
I also run ts-node with following import cjs path but still got an error of
if I import with import Pocketbase from "pocketbase/cjs". The typescript complain
Thanks for the awsome project. |
This was recently discussed in #34. In short you have 2 options:
|
@ganigeorgiev Thanks for directing me to the right discussion. I've tried option1 it works! The only problem left is missing type definition when using I'll try to find a workaround for this. Thanks Again! |
Did you ever find a solution? None of the esnext/module type works for me. Having type definitions would be nice |
if you can't enable esm for some reason you can make a helper like this to get the imported module and the type: export const getPocketBase = async () => {
const { default: PocketBase } = await import("pocketbase")
return PocketBase
}
export type PocketBaseType = Awaited<
ReturnType<typeof getPocketBase>
>["prototype"] then use it like: import { getPocketBase, PocketBaseType } from "get-pocketbase"
function foo() {
const PocketBase = await getPocketBase()
// do stuff with pb here
}
// if you need the type elsewhere
function doAThingWithProvidedPocketBaseClient(pb: PocketBaseType) {
// pb will be typed as a pocket base client here
} |
I'm really looking forward to use PocketBase. Great project.
Here is what happened when I tried to require the library in Node:
I also got this error when importing PocketBase in an empty Vite app:
The text was updated successfully, but these errors were encountered: