t3-oss / create-t3-turbo

Clean and simple starter repo using the T3 Stack along with Expo React Native

Home Page:https://turbo.t3.gg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug: unable to import other workspace packages into expo

Mirthis opened this issue · comments

Provide environment information

System:
OS: Windows 11 10.0.22631
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Memory: 2.81 GB / 15.80 GB

Binaries:
Node: 21.7.1 - C:\Program Files\nodejs\node.EXE
npm: 10.5.0 - C:\Program Files\nodejs\npm.CMD
pnpm: 8.15.5 - ~\AppData\Local\pnpm\pnpm.EXE

Describe the bug

I'm facing an issue when importing packages created in other workspaces into expo (I assume this is not the case for devDependencies as they don't end up in the final bundle).

Android Bundling failed 4976ms (C:\Users\mirth\Coding\create-t3-turbo\node_modules\expo-router\entry.js)
Unable to resolve "@acme/validators" from "src\app\index.tsx"

I originally found this problem when creating a new lib workspace that I'm able to use within the api workspace, but not in the expo workspace.

Just to rule out me having made any mistake with the new package, I've tried the same with the existing validators package and I'm getting the same error.

I can see @acme/validators under the node_modules folder in the expo directory but it looks like the metro bundler cannot resolve it.

I think this may be similar to the issue report here.

To replicate this I attached a repo where I have:

  • cloned a the latest create-t3-turbo repo
  • added and exported a new variable TEST_IMPORT in /packages/validators/src/index.ts
  • added "@acme/validators": "workspace:*" in package.json in app/expo
  • imported the new variable and console.log it in app\expo\src\app\index.tsx

Link to reproduction

https://github.com/Mirthis/create-t3-turbo-expo-import

To reproduce

  • clone the repo
  • set environment variables as usual
  • run the application
  • the TEST_IMPORT variable defined in @acme\validators is going to be logged in the console in the next app while the expo app will throw a Unable to resolve "@acme/validators" error

Additional information

No response

I have now added the following to the same packages/validators/package.json file and things seems to be working ok:

"main": "src/index.ts"

It would be good if someone can validate this as I have no experience working with a monorepo.


Basically, after looking more in depth at the error shown on my device it looks like the module was resolved from @acme/validators/index.ts instead of @acme/validators/src/index.ts so not taking into account what defined under exports in package.json:

exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "default": "./src/index.ts"
    }
  },

Maybe try this https://metrobundler.dev/docs/package-exports/

Thanks!
I think I may have found a solution but I'll go through this.

commented

@Mirthis just following up here - I'm trying to use @acme/validators inside expo as well... did you simply add the main field to package.json, create a new build, and then viola?

@adamspotlite yes that should do it.

So in package.json under /apps/expo add "@acme/validators": "workspace:^0.1.0" to your dependencies.
If with just this your package is not resolved then in package.json under packages\validators add "main": "src/index.ts"

After each change re-run pnpm i

Hey, I had this same problem. After adding "main": "src/index.ts" to @acme/validators's package.json, it worked for me