denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.18k stars 623 forks source link

node:xxx CORS error #2207

Closed tetsuya28 closed 8 months ago

tetsuya28 commented 8 months ago

With islands component like following, I got CORS error. Why Deno or fresh accesses to node:xxx, such as node:prcess, node:url, node:tls, etc. And, how to fix this error.

export default function Sidebar() {
    useEffect(() => {
        (async () => {
            try {
                const client = new MyClient();
                                 ...
            } catch (err) {
                console.error(err);
            }
        })()
    }, [])

// Just set url in constructor
export class MyClient {
  apiBaseUrl: string;

  constructor() {
    this.apiBaseUrl = config.BACKEND_ENDPOINT; // http://localhost:8080
  }
}

s 178 s 179

fresh: v1.6.1

marvinhagemeister commented 8 months ago

Sounds like you're pulling in code into your islands which is not meant to run in the browser, but rather on the server. We can't help you more based on the snippet you provided because the culprit is likely the various imports in that island files. Or the files that are imported in the island import another file that in turn pulls in server-only dependencies.

tetsuya28 commented 8 months ago

I found server-only dependencies from imported file. And, when remove the code, the code works fine. Thanks.