kiliman/remix-flat-routes

TypeError: flatRoutes is not a function

Closed this issue · 5 comments

I am getting an error trying to run a brand new Remix installation with the flat-routes
Remix Version 2.12.0

npx create-remix@latest
npm i -D remix-flat-routes

Here is my vite.config.ts
Copied the routes part from Kent's epicweb starter

import { vitePlugin as remix } from "@remix-run/dev";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
  plugins: [
    remix({
      future: {
        v3_fetcherPersist: true,
        v3_relativeSplatPath: true,
        v3_throwAbortReason: true,
      },
      routes: async (defineRoutes) => {
        return flatRoutes('routes', defineRoutes, {
          ignoredRouteFiles: [
            '.*',
            '**/*.css',
            '**/*.test.{js,jsx,ts,tsx}',
            '**/__*.*',
            // This is for server-side utilities you want to colocate
            // next to your routes without making an additional
            // directory. If you need a route that includes "server" or
            // "client" in the filename, use the escape brackets like:
            // my-route.[server].tsx
            '**/*.server.*',
            '**/*.client.*',
          ],
        })
      },
    }),
    tsconfigPaths(),
  ],
});

Then run npm run dev and you will get the error as well.
Not sure what I am doing wrong?

Clearly something because it works when use epicweb starter (but it's too bloated for my needs), and clearly other people are using it.

So what is the secret ?

EDIT: Can not get the vite.config.ts text inside the code blocks, even though wrapped it inside back-ticks

You need to import the function in your vite.config.ts

import { flatRoutes } from "remix-flat-routes";

I've tried that and it still won't work for me.
I obviously missed it out of my posting above but I assure you it is there in my vite config

Anything else you can think of please?

Do you have a repo I can look at?

You can also try deleting node_modules and run npm install again.

I will upload the repo and post a link here.
Will try the node_modules trick first

The node_modules trick worked........
Wonder what was causing it to do that.
It's not like there's anything else installed.

Anyway, thanks for your help, much appreciated 😄