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

bug: unable to import other workspace packages into expo #953

Open
Mirthis opened this issue Mar 28, 2024 · 5 comments
Open

bug: unable to import other workspace packages into expo #953

Mirthis opened this issue Mar 28, 2024 · 5 comments

Comments

@Mirthis
Copy link

Mirthis commented Mar 28, 2024

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

@juliusmarminge
Copy link
Member

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

@Mirthis
Copy link
Author

Mirthis commented Mar 28, 2024

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"
    }
  },

@Mirthis
Copy link
Author

Mirthis commented Mar 28, 2024

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

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

@adamspotlite
Copy link

adamspotlite commented Apr 25, 2024

@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?

@Mirthis
Copy link
Author

Mirthis commented Apr 25, 2024

@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

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

3 participants