supabase-community / chatgpt-your-files

Production-ready MVP for securely chatting with your documents using pgvector
https://youtu.be/ibzlEQmgPPY
365 stars 126 forks source link

supabase folder should be excluded in next.config #6

Closed kleenkanteen closed 12 months ago

kleenkanteen commented 1 year ago

Bug report

Describe the bug

I am developing using the cloud, no docker.

When I run npm run build, I get this error:

image

Text version:

./supabase/functions/_lib/markdown-parser.ts:1:35
Type error: Cannot find module 'mdast' or its corresponding type declarations.

> 1 | import { Root, RootContent } from 'mdast';
    |                                   ^
  2 | import { fromMarkdown } from 'mdast-util-from-markdown';
  3 | import { toMarkdown } from 'mdast-util-to-markdown';
  4 | import { toString } from 'mdast-util-to-string';

In next.config.js I tried adding to the nextConfig object exclude: ['supabase'], but it does not work.

I tried adding this too but no banana:

  experimental: {
    serverActions: true,
    ignore: [
      '/supabase/functions/**/*',
    ],
  },

Here is above both tries in the next.config file:

/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    serverActions: true,
    ignore: [
      '/supabase/functions/**/*',
    ],
  },
  exclude: ['supabase/functions'],
  webpack: (config) => {
    config.resolve.alias = {
      ...config.resolve.alias,
      sharp$: false,
      'onnxruntime-node$': false,
    };
    return config;
  },
};

module.exports = nextConfig;

As a workaround I deleted every folder inside supabase/functions except lib. And I deleted the markdown-parser.ts file there since that's where the issue was. Then npm run build worked.

Also why is mdast used? The npm page for it says it's deprecated and it's actually renamed remark, https://www.npmjs.com/package/mdast

kleenkanteen commented 1 year ago

I think I found the fix. In the base tsconfig.json, replace line 27 with this "exclude": ["node_modules", "supabase/functions"]. This will ignore that folder during build.

Source of where I got help from: https://github.com/vercel/next.js/discussions/11113#discussioncomment-37588. Read, "What is included in the build seems to depend a lot on tsconfig.json when you use TypeScript. So excluding failing files seems to work for me."

But supabase/functions/_lib/database.ts is imported into app\chat\page.tsx on line 7. You will have to copy the former into the lib folder and then import it from there.

kleenkanteen commented 1 year ago

You might ask why not run npm run dev? Because when I run it and try to sign up, it gives me the error "Error: Hydration failed because the initial UI does not match what was rendered on the server." That was with the starter idk why it happened.

kleenkanteen commented 1 year ago

The tsconfig.json workaround is not ideal since typescript errors don't show up. Just made a silly error that only got caught after deploying the edge function and running it.

gregnr commented 1 year ago

Thanks for reporting @kleenkanteen! I created a PR to address the build specific issues: #9

Let's address the npm run dev issue in #8

gregnr commented 12 months ago

Fixed via #9. Feel free to reopen/comment if you experience any more build related issues!