one icon indicating copy to clipboard operation
one copied to clipboard

Loaders Do Not Work: traverse is not a function.

Open barziahmed opened this issue 1 year ago ‱ 3 comments

If I add the loader to my index page, like this:

import { Image } from '@tamagui/image-next'
import { Text, YStack } from 'tamagui'
import oneBall from '~/public/app-icon.png'
import { useLoader } from 'one'

export async function loader() {
  return {
    user: 'tamagui'
  }
}

export  function HomePage() {
  const data = useLoader(loader)

	return (
		<YStack
			bg='$color1'
			mih='100%'
			gap='$4'
			ai='center'
			jc='center'
			f={1}
		>
			<Text fontSize={20}>Hello,     {data.user}</Text>
			<Image
				src={oneBall}
				width={128}
				height={128}
			/>
		</YStack>
	)
}

I will get the following error:

[vite] program reload
[vite] An error happened during full reload
[vite] cannot find entry point module 'virtual:one-entry'.
Error: [vite] cannot find entry point module 'virtual:one-entry'.
    at <anonymous> (/Users/panda/Desktop/monorepo/node_modules/vite/dist/node/chunks/dep-0AosnpPU.js:51428:13)
    at processTicksAndRejections (native)
 đŸȘ„ app/index.tsx
24 |     referenced = findReferencedIdentifiers(ast),
25 |     removed = {
26 |       loader: !1,
27 |       generateStaticParams: !1
28 |     };
29 |   traverse(ast, {
       ^
TypeError: traverse is not a function. (In 'traverse(ast, {
    ExportNamedDeclaration(path) {
      if (path.node.declaration && path.node.declaration.type === "FunctionDeclaration") {
        if (!path.node.declaration.id)
          return;
        const functionName = path.node.declaration.id.name;
        (functionName === "loader" || functionName === "generateStaticParams") && (path.remove(), removed[functionName] = !0);
      } else
        path.node.declaration && path.node.declaration.type === "VariableDeclaration" && path.node.declaration.declarations.forEach((declarator, index) => {
          if (declarator.id.type === "Identifier" && (declarator.id.name === "loader" || declarator.id.name === "generateStaticParams")) {
            const declaration = path.get("declaration.declarations." + index);
            Array.isArray(declaration) || (declaration.remove(), removed[declarator.id.name] = !0);
          }
        });
    }
  })', 'traverse' is undefined)
      at /Users/panda/Desktop/monorepo/node_modules/one/dist/esm/vite/plugins/clientTreeShakePlugin.mjs:29:3
      at transformTreeShakeClient (/Users/panda/Desktop/monorepo/node_modules/one/dist/esm/vite/plugins/clientTreeShakePlugin.mjs:17:3)
      at /Users/panda/Desktop/monorepo/node_modules/one/dist/esm/vite/plugins/clientTreeShakePlugin.mjs:15:37
      at transform (/Users/panda/Desktop/monorepo/node_modules/one/dist/esm/vite/plugins/clientTreeShakePlugin.mjs:14:21)
      at /Users/panda/Desktop/monorepo/node_modules/vite/dist/node/chunks/dep-0AosnpPU.js:47220:19
      at processTicksAndRejections (native:1:1)

Bun v1.1.42 (macOS arm64)
error: script "dev" exited with code 1

I use one version 1.1.375, with react 19.

barziahmed avatar Dec 30 '24 17:12 barziahmed

what starter template / what platform / how can we repro?

natew avatar Dec 30 '24 20:12 natew

@natew minimal tamagui template, macO, and using bun. Using latest version of all of them as time of writing.

barziahmed avatar Dec 31 '24 08:12 barziahmed

@natew Just started trying out this framework and I am having the same issue. I am using the tamagui starter and just added a loader to app/index.tsx and got the same error.

lukeshay avatar Mar 26 '25 17:03 lukeshay

I bumped into this issue as well, using Bun 1.2.19 and One 1.1.506.

gyulavoros avatar Jul 25 '25 09:07 gyulavoros

Hi @gyulavoros @lukeshay - thanks for providing the info, but unfortunately I'm unable to reproduce the issue using npx one, Minimal Tamagui, and bun.

Tried with Node.js versions 22.17.1, 20.18.0, and 24.3.0.

jq .version node_modules/@babel/traverse/package.json shows "7.28.0".

Could you share your Node.js version, along with your package.json and bun.lock files to help troubleshoot further?

zetavg avatar Jul 26 '25 19:07 zetavg

Hi @zetavg, thank you for looking into this!

Here's an example project for repro: hello-world.zip

Please note, that I use bun --bun run dev to run the project (--bun). Running bun run dev works. I had the assumption that without the --bun flag, Vite would actually use Node to run the project, but I've just checked the Activity Monitor, and it doesn't seem to be the case. đŸ€”

Hope it helps to investigate!

Image

This was the project setup:

bunx one
warn: incorrect peer dependency "[email protected]"

warn: incorrect peer dependency "[email protected]"

warn: incorrect peer dependency "[email protected]"

warn: incorrect peer dependency "[email protected]"

  Hello. Let's create a new ①  app...

✔ Name 
 hello-world


✔ Template â€ș Minimal

⠙ Creating...


hello-world created!


✔ Package Manager: â€ș bun


Installing with bun...

bun install v1.2.19 (aad3abea)
warn: incorrect peer dependency "[email protected]"

warn: incorrect peer dependency "@expo/[email protected]"

warn: incorrect peer dependency "[email protected]"

+ @react-native-community/[email protected]
+ @types/[email protected] (v19.1.8 available)
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected] (v19.1.0 available)
+ [email protected] (v0.80.2 available)
+ [email protected] (v4.0.0 available)
+ [email protected]
+ [email protected]
+ [email protected] (v0.21.0 available)

1026 packages installed [3.43s]

Blocked 3 postinstalls. Run `bun pm untrusted` for details.
bun install completed successfully.

Done! Created a new project under ./hello-world

This is how I run the project:

bun --bun run dev
$ one dev
[vite] connected.
10:58:05 AM [vite] (client) Re-optimizing dependencies because vite config has changed
10:58:05 AM [vite] (ssr) Re-optimizing dependencies because vite config has changed

Server running on âȘą

  ➜  Local:   http://localhost:8081/
  ➜  Network: http://192.168.1.112:8081/

â€ș Press ow │ open web
â€ș Press oi │ open app in iOS Simulator
â€ș Press oa │ open app in Android Emulator
â€ș Press oe │ open editor
â€ș Press qr │ show Expo Go QR code
â€ș Press dt │ open React Native DevTools
â€ș Press ?  │ show this menu

 â“”  [ssg] http://localhost:8081/ resolved to app/index.tsx
10:58:08 AM [vite] Internal server error: traverse is not a function. (In 'traverse(ast, {
    ExportNamedDeclaration(path) {
      if (path.node.declaration && path.node.declaration.type === "FunctionDeclaration") {
        if (!path.node.declaration.id)
          return;
        const functionName = path.node.declaration.id.name;
        (functionName === "loader" || functionName === "generateStaticParams") && (path.remove(), removed[functionName] = !0);
      } else
        path.node.declaration && path.node.declaration.type === "VariableDeclaration" && path.node.declaration.declarations.forEach((declarator, index) => {
          if (declarator.id.type === "Identifier" && (declarator.id.name === "loader" || declarator.id.name === "generateStaticParams")) {
            const declaration = path.get("declaration.declarations." + index);
            Array.isArray(declaration) || (declaration.remove(), removed[declarator.id.name] = !0);
          }
        });
    }
  })', 'traverse' is undefined)
  Plugin: one-client-tree-shake
  File: /Users/gyulavoros/Downloads/temp/hello-world/app/index.tsx:33:3
      at transformTreeShakeClient (/Users/gyulavoros/Downloads/temp/hello-world/node_modules/one/dist/esm/vite/plugins/clientTreeShakePlugin.mjs:33:3)
      at transformTreeShakeClient (/Users/gyulavoros/Downloads/temp/hello-world/node_modules/one/dist/esm/vite/plugins/clientTreeShakePlugin.mjs:22:41)
      at handler (/Users/gyulavoros/Downloads/temp/hello-world/node_modules/one/dist/esm/vite/plugins/clientTreeShakePlugin.mjs:18:134)
      at handler (/Users/gyulavoros/Downloads/temp/hello-world/node_modules/one/dist/esm/vite/plugins/clientTreeShakePlugin.mjs:17:21)
      at transform (/Users/gyulavoros/Downloads/temp/hello-world/node_modules/vite/dist/node/chunks/dep-BHkUv4Z8.js:31274:51)
      at transform (/Users/gyulavoros/Downloads/temp/hello-world/node_modules/vite/dist/node/chunks/dep-BHkUv4Z8.js:31256:18)
      at loadAndTransform (/Users/gyulavoros/Downloads/temp/hello-world/node_modules/vite/dist/node/chunks/dep-BHkUv4Z8.js:26451:48)
      at processTicksAndRejections (native:7:39)

gyulavoros avatar Jul 28 '25 09:07 gyulavoros

I think this is likely more a bun issue than our issue, in that they have different module resolution. Does it work on the latest bun now? We don't support bun --bun atm, I'm adding that to the docs. If someone wants to help contribute happy to accept it!

natew avatar Aug 14 '25 19:08 natew

@natew with the latest bun (1.2.20), it still doesn't work, but there's a different error:

bun --bun dev
$ one dev
[vite] connected.
✘ [ERROR] Could not resolve "@babel/runtime/helpers/interopRequireDefault"

    ../../.bun/install/cache/[email protected]@@@1/dist/cjs/index.js:3:37:
      3 │ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
        â•”                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@babel/runtime/helpers/interopRequireDefault" as external to exclude it
  from the bundle, which will remove this error and leave the unresolved path in the bundle. You can
  also surround this "require" call with a try/catch block to handle this failure at run-time
  instead of bundle-time.

✘ [ERROR] Could not resolve "@babel/runtime/helpers/interopRequireDefault"

    ../../.bun/install/cache/[email protected]@@@1/dist/cjs/exports/ProgressBar/index.js:13:37:
      13 │ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
         â•”                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@babel/runtime/helpers/interopRequireDefault" as external to exclude it
  from the bundle, which will remove this error and leave the unresolved path in the bundle. You can
  also surround this "require" call with a try/catch block to handle this failure at run-time
  instead of bundle-time.

✘ [ERROR] Could not resolve "@babel/runtime/helpers/interopRequireDefault"

    ../../.bun/install/cache/[email protected]@@@1/dist/cjs/exports/createElement/index.js:13:37:
      13 │ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
         â•”                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@babel/runtime/helpers/interopRequireDefault" as external to exclude it
  from the bundle, which will remove this error and leave the unresolved path in the bundle. You can
  also surround this "require" call with a try/catch block to handle this failure at run-time
  instead of bundle-time.

...

And it continues for ~9000 lines.

gyulavoros avatar Aug 15 '25 09:08 gyulavoros