pocketbase / js-sdk

PocketBase JavaScript SDK
https://www.npmjs.com/package/pocketbase
MIT License
2.04k stars 120 forks source link

Problems with vite #79

Closed DivyanshuBhoyar closed 1 year ago

DivyanshuBhoyar commented 1 year ago

Do not know how to load path pockebase

On solid-start-0.2.5, with SSR and without SSR enabled

ganigeorgiev commented 1 year ago

Could you provide a little more details - what PocketBase JS SDK version do you use, how are you loading the SDK, do you use TypeScript, etc.

ganigeorgiev commented 1 year ago

I cannot reproduce the issue.

I've tested with the default solid-start template:

  1. npm init solid
  2. npm install pocketbase --save
  3. Initialized the client using the ES import:

    import PocketBase from "pocketbase";
    
    const pb = new PocketBase("https://pocketbase.io");

I'll close the issue because I don't think it is related to the SDK but feel free to provide more details about your setup and I'll try to help.

DivyanshuBhoyar commented 1 year ago

Here are my dependencies "devDependencies": { "solid-start-node": "^0.2.0", "typescript": "^4.8.4", "vite": "^3.1.8" }, "dependencies": { "@solidjs/meta": "^0.28.0", "@solidjs/router": "^0.5.0", "pocketbase": "0.8.0-rc4", "solid-js": "^1.6.0", "solid-start": "^0.2.0", "undici": "^5.11.0" }

The src/routes/index.tsx file to reproduce the issue :

import { Title } from "solid-start";
import Counter from "~/components/Counter";
import PocketBase from "pocketbase";
import { createServerAction$ } from "solid-start/server";

export default function Home() {
  const pb = new PocketBase("http://127.0.0.1:8090");

  const data = {
    username: "test_username",
    email: "dishankb@gmail.com",
    emailVisibility: true,
    password: "12345678",
    passwordConfirm: "12345678",
    name: "test",
  };

  const [acting, act] = createServerAction$(async (args) => {
    // do something
    const record = await pb.collection("users").create(data);
    // (optional) send an email verification request
    await pb.collection("users").requestVerification("dishankb@gmail.com");
  });

  return (
    <main>
      <Title>Hello World</Title>
      <h1>Hello world!</h1>
      <Counter />
      <p>
        Visit{" "}
        <a href="https://start.solidjs.com" target="_blank">
          start.solidjs.com
        </a>{" "}
        to learn how to build SolidStart apps.
      </p>
      <button onClick={() => act()}>click me</button>
    </main>
  );
}

And this is the error image

@ganigeorgiev trying pocketbase for first time, unsure how to setup in this case.

ganigeorgiev commented 1 year ago

@DivyanshuBhoyar

I'm not sure what is the reason for the error and as mentioned previously I cannot reproduce it with the starter template (aka. npm init solid).

Make sure that the PocketBase JS SDK was instanlled by checking if there is a pocketbase folder inside your node_modules (also you can use the latest PocketBase 0.8.0 release).

Also make sure that the PocketBase binary is not placed inside the src/routes/ directory, because depending how your node resolver is configured it is also possible that import PocketBase from "pocketbase" will try to load the binary instead of the node module.

As an alternative you can also start from scratch and try to reproduce the error by initializing new starter template (aka. npm init solid).

DivyanshuBhoyar commented 1 year ago

Thanks @ganigeorgiev Renaming pocketbase binary to pocketbase-bin seems to have solved the problem with same code.