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

tsr generate error when using virtual-file-routes #2816

Open
carriebae opened this issue Nov 21, 2024 · 1 comment
Open

tsr generate error when using virtual-file-routes #2816

carriebae opened this issue Nov 21, 2024 · 1 comment

Comments

@carriebae
Copy link

Which project does this relate to?

Router

Describe the bug

When applying 'basic-virtual-inside-file-based' case in app in nx, tsr generate error occurs.

PS C:\Users\9480335\workspace\refers\nx-tanstack-router\apps\nxtest> npx tsr generate

♻️  Generating routes...
TypeError: nodes.map is not a function
    at getRouteNodesRecursive (C:\Users\9480335\workspace\refers\nx-tanstack-router\node_modules\.pnpm\@[email protected]\node_modules\@tanstack\router-generator\dist\cjs\filesystem\virtual\getRouteNodes.cjs:49:11)
    at Module.getRouteNodes (C:\Users\9480335\workspace\refers\nx-tanstack-router\node_modules\.pnpm\@[email protected]\node_modules\@tanstack\router-generator\dist\cjs\filesystem\virtual\getRouteNodes.cjs:27:26)
    at recurse (C:\Users\9480335\workspace\refers\nx-tanstack-router\node_modules\.pnpm\@[email protected]\node_modules\@tanstack\router-generator\dist\cjs\filesystem\physical\getRouteNodes.cjs:65:71)
    at async C:\Users\9480335\workspace\refers\nx-tanstack-router\node_modules\.pnpm\@[email protected]\node_modules\@tanstack\router-generator\dist\cjs\filesystem\physical\getRouteNodes.cjs:87:11
    at async Promise.all (index 1)
    at async recurse (C:\Users\9480335\workspace\refers\nx-tanstack-router\node_modules\.pnpm\@[email protected]\node_modules\@tanstack\router-generator\dist\cjs\filesystem\physical\getRouteNodes.cjs:82:5)
    at async Module.getRouteNodes (C:\Users\9480335\workspace\refers\nx-tanstack-router\node_modules\.pnpm\@[email protected]\node_modules\@tanstack\router-generator\dist\cjs\filesystem\physical\getRouteNodes.cjs:157:3)
    at async Module.generator (C:\Users\9480335\workspace\refers\nx-tanstack-router\node_modules\.pnpm\@[email protected]\node_modules\@tanstack\router-generator\dist\cjs\generator.cjs:66:27)
    at async Module.generate (C:\Users\9480335\workspace\refers\nx-tanstack-router\node_modules\.pnpm\@[email protected]\node_modules\@tanstack\router-cli\dist\cjs\generate.cjs:6:5)
    at async C:\Users\9480335\workspace\refers\nx-tanstack-router\node_modules\.pnpm\@[email protected]\node_modules\@tanstack\router-cli\dist\cjs\index.cjs:28:5
PS C:\Users\9480335\workspace\refers\nx-tanstack-router\apps\nxtest>

routes path (~/apps/nxtest/src/pages)
Image

__virtual.ts

import {
  defineVirtualSubtreeConfig,
  index,
  physical,
  route,
} from '@tanstack/virtual-file-routes';

// this just shows that you can use an async function to define your virtual routes
export default defineVirtualSubtreeConfig(async () => [
  index('home.tsx'),
  route('$postId', 'details.tsx'),
  physical('/inception', 'lets-go'),
]);

tsr.config.json

{
    "routesDirectory": "./src/pages",
    "generatedRouteTree": "./src/routeTree.gen.ts",
    "routeFileIgnorePrefix": "-"
  }

If I ignore the posts directory, it works fine without error.

Your Example Website or App

https://github.com/carriebae/nx-tanstack-router

Steps to Reproduce the Bug or Issue

  1. git clone https://github.com/carriebae/nx-tanstack-router
  2. cd ~/nx-tanstack-router
  3. pnpm i
  4. cd apps/nxtest
  5. npx tsr generate

Expected behavior

tsr generate should work without errors even with __virtual.ts included.

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Chrome
  • Version: -

Additional context

No response

@davidturissini
Copy link

Also coming across this. Setting type: "module" in my package.json file fixes it but predictably, causes other issues. I haven't done any digging but it seems like something is being mis-translated between require and import.

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