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

Compatibility with Vite #278

Closed
nickcotton opened this issue Jun 4, 2021 · 4 comments
Closed

Compatibility with Vite #278

nickcotton opened this issue Jun 4, 2021 · 4 comments

Comments

@nickcotton
Copy link

Hi! I've recently been exploring migrating our rails app from webpack/webpacker to Vite.

I'm getting an error whenever I try to import a specific route. I do not get the same error when using webpacker.

import { plannerAdminPagePreviewPath } from "@/app/javascript/routes";

undefined is not an object (evaluating 'object[part] = routes')

CleanShot 2021-06-04 at 09 09 26@2x

I've seen similar errors mentioned before but not in relation to Vite.

Do you know if I'm missing something? Is there a config step I've left out? Thanks!

@bogdan
Copy link
Collaborator

bogdan commented Jun 4, 2021

Set namespace = nil in your Js routes configuration file. That should help. If not, consider upgrade to 2.x.

@nickcotton
Copy link
Author

Thanks, that worked! For anyone else that comes across this, I was using 2.x already.

@bogdan
Copy link
Collaborator

bogdan commented Jun 4, 2021

Current 2.x default for namespace is this:

{
    namespace: -> { defined?(Webpacker) ? nil : "Routes" },
}

Is there any way I can detect Vite env setup easily and ensure it is nil there too?

@nickcotton
Copy link
Author

I'm not 100% sure. I've been using the https://github.com/ElMassimo/vite_ruby gem to get Vite working but that wouldn't necessarily be true for everyone. Perhaps there's something useful there though.

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

No branches or pull requests

2 participants