Skip to content
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

Remix + vite using v1 routing (@remix-run/v1-route-convention) doesnt work? #8744

Closed
cliffordfajardo opened this issue Feb 13, 2024 · 7 comments

Comments

@cliffordfajardo
Copy link
Contributor

cliffordfajardo commented Feb 13, 2024

Reproduction

I created a repo containing

  1. fresh unmodified remix-vite express app
  2. modified remix-vite express app attempting to use @remix-run/v1-route-convention

Github Repo: https://github.com/cliffordfajardo/bug-remix-vite-using-v1-routing/tree/main

CleanShot 2024-02-13 at 12 15 03@2x

Reproduction Steps

1.Create a new remix app using vite express

npx create-remix --template remix-run/remix/templates/unstable-vite-express
  1. install [@remix-run/v1-route-convention](https://github.com/remix-run/v1-compat-utils)
  2. Rename routes/_index.ts to routes/index.ts

System Info

System:
    OS: macOS 14.3.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 116.60 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.5.0 - ~/.volta/tools/image/node/20.5.0/bin/node
    Yarn: 1.22.10 - ~/.volta/tools/image/yarn/1.22.10/bin/yarn
    npm: 9.8.0 - ~/.volta/tools/image/node/20.5.0/bin/npm
    bun: 1.0.3 - ~/.bun/bin/bun
  Browsers:
    Chrome: 121.0.6167.139
    Chrome Canary: 117.0.5849.2
    Safari: 17.3.1
  npmPackages:
    @remix-run/dev: ^2.6.0 => 2.6.0 
    @remix-run/express: ^2.6.0 => 2.6.0 
    @remix-run/node: ^2.6.0 => 2.6.0 
    @remix-run/react: ^2.6.0 => 2.6.0 
    @remix-run/v1-route-convention: ^0.1.4 => 0.1.4 
    vite: ^5.0.0 => 5.1.1

Used Package Manager

npm

Expected Behavior

After creating a fresh remix app, I should be able to use [@remix-run/v1-route-convention](https://github.com/remix-run/v1-compat-utils) package

Actual Behavior

Remix + Vite doesnt seem to work with @remix-run/v1-route-convention

npm run dev

/Users/cfajardo/Downloads/bug--remix-vite-using-v1-routing/remix_2_6_0_v1_routes/node_modules/@remix-run/dev/dist/config/flat-routes.js:38
    if (!value) throw new Error("Cannot add empty string to PrefixLookupTrie");
                      ^

Error: Cannot add empty string to PrefixLookupTrie
    at PrefixLookupTrie.add (/Users/cfajardo/Downloads/bug--remix-vite-using-v1-routing/remix_2_6_0_v1_routes/node_modules/@remix-run/dev/dist/config/flat-routes.js:38:23)
    at flatRoutesUniversal (/Users/cfajardo/Downloads/bug--remix-vite-using-v1-routing/remix_2_6_0_v1_routes/node_modules/@remix-run/dev/dist/config/flat-routes.js:141:18)
    at Object.flatRoutes (/Users/cfajardo/Downloads/bug--remix-vite-using-v1-routing/remix_2_6_0_v1_routes/node_modules/@remix-run/dev/dist/config/flat-routes.js:97:23)
    at Object.resolveConfig (/Users/cfajardo/Downloads/bug--remix-vite-using-v1-routing/remix_2_6_0_v1_routes/node_modules/@remix-run/dev/dist/config.js:164:33)
    at async updateRemixPluginContext (/Users/cfajardo/Downloads/bug--remix-vite-using-v1-routing/remix_2_6_0_v1_routes/node_modules/@remix-run/dev/dist/vite/plugin.js:314:9)
    at async config (/Users/cfajardo/Downloads/bug--remix-vite-using-v1-routing/remix_2_6_0_v1_routes/node_modules/@remix-run/dev/dist/vite/plugin.js:506:7)
    at async runConfigHook (file:///Users/cfajardo/Downloads/bug--remix-vite-using-v1-routing/remix_2_6_0_v1_routes/node_modules/vite/dist/node/chunks/dep-94_H5fT6.js:68149:25)
    at async resolveConfig (file:///Users/cfajardo/Downloads/bug--remix-vite-using-v1-routing/remix_2_6_0_v1_routes/node_modules/vite/dist/node/chunks/dep-94_H5fT6.js:67608:14)
    at async _createServer (file:///Users/cfajardo/Downloads/bug--remix-vite-using-v1-routing/remix_2_6_0_v1_routes/node_modules/vite/dist/node/chunks/dep-94_H5fT6.js:64224:20)
    at async file:///Users/cfajardo/Downloads/bug--remix-vite-using-v1-routing/remix_2_6_0_v1_routes/server.js:12:7
@cliffordfajardo cliffordfajardo changed the title Remix + VIte using v1 routing doesnt work? - @remix-run/v1-route-convention Remix + vite using v1 routing (@remix-run/v1-route-convention) doesnt work? Feb 13, 2024
@markdalgleish
Copy link
Member

markdalgleish commented Feb 13, 2024

I wasn't able to reproduce this issue, both manually and when running your repro.

I've pushed my attempt at a manual reproduction here. Can you check whether this works for you? https://github.com/markdalgleish/remix-vite-express-with-v1-routes

By the way, I noticed that a sync routes function in the Remix Vite plugin options is incorrectly flagged as a type error (and that you had to work around this too), so I've opened a PR to fix this: #8745

@cliffordfajardo
Copy link
Contributor Author

cliffordfajardo commented Feb 13, 2024

@markdalgleish - thanks for the quick response

Turns out this error from using @remix-run/v1-route-convention comes from accidenally having a .DS_STORE file inside the routes folder: #6256

I deleted the .DS_STORE file & the v1 routes started working & the build does generate build/server

# ran from the top of the root of my repo
find . -name ".DS_Store" -type f -delete

@kiliman
Copy link
Collaborator

kiliman commented Feb 13, 2024

@cliffordfajardo Do you set the ignoredFilePatterns to ignore dotfiles?

/** @type {import(https://github.com/remix-run/remix/tree/master/packages/remix-dev).AppConfig} */
module.exports = {
  // Tell Remix to ignore everything in the routes directory.
  // We'll let `createRoutesFromFolders` take care of that.
  ignoredRouteFiles: ["**/*"],
  routes: (defineRoutes) => {
    // `createRoutesFromFolders` will create routes for all files in the
    // routes directory using the same default conventions as Remix v1.
    return createRoutesFromFolders(defineRoutes, {
      // If you're already using `ignoredRouteFiles` in your Remix config,
      // you can move them to `ignoredFilePatterns` in the plugin's options.
      // ignore dotfiles
      ignoredFilePatterns: ["**/.*", "**/*.css"],
    });
  },
};

@cliffordfajardo
Copy link
Contributor Author

cliffordfajardo commented Feb 14, 2024

Do you set the ignoredFilePatterns to ignore dotfiles? - @kiliman

For the PrefixLookupTrie error, the problem was indeed due to having a .DS_STORE file inside of routes folder, so I just deleted it the file:

# ran from root of my remix project - then restarted dev server
find . -name ".DS_Store" -type f -delete

I was curious about the ignoredRouteFiles: ["**/*"] at the root of the remix config and ignoredFilePatterns inside of createRoutesFromFolders - they dont work when using them inside of vite.config.js

When you're using vite, the docs recommend not having remix.config.js file anymore
https://remix.run/docs/en/main/future/vite#configuration

Created a bug reproduction repo
https://github.com/cliffordfajardo/bug-remix-v1-routing-vite-config

image

@markdalgleish
Copy link
Member

@cliffordfajardo Looks like you also need to exclude dotfiles in ignoredRouteFiles:

remix({
  ignoredRouteFiles: ["**/*", "**/.*"],
  routes: (defineRoutes) => {
    return createRoutesFromFolders(defineRoutes, {
      ignoredFilePatterns: ["**/.*", "**/*.css"],
    });
  },
})

@markdalgleish
Copy link
Member

I've fixed this in the v1-route-convention readme: https://github.com/remix-run/v1-compat-utils/tree/main/packages/v1-route-convention

@markdalgleish
Copy link
Member

I've also opened a PR updating all the Vite templates to set ignoredRouteFiles to ["**/.*"] to avoid this issue coming up in that context too: #8800

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants