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

Cannot build next.js project if expo-router is in node_modules #363

Closed
tamagokun opened this issue Mar 9, 2023 · 4 comments
Closed

Cannot build next.js project if expo-router is in node_modules #363

tamagokun opened this issue Mar 9, 2023 · 4 comments

Comments

@tamagokun
Copy link

tamagokun commented Mar 9, 2023

Summary

I believe this may be the same issue as this comment: #323 (comment)

Running next build will cause next.js to do type checking on the project. Even though tsconfig is setup properly (proper include, exclude: ["node_modules"], skipLibCheck: true), TS will still start type checking expo-router and throw an error:

../../node_modules/expo-router/src/fork/getStateFromPath.ts:475:3
Type error: Unused '@ts-expect-error' directive.

  473 |   parentScreens.push(screen);
  474 |
> 475 |   // @ts-expect-error
      |   ^
  476 |   const config = routeConfig[screen];
  477 |
  478 |   if (typeof config === "string") {

To be clear, i'm not using expo-router on web, or in next.js. It's part of a shared component that gets used in a native expo project and a next.js web project.

Minimal reproducible example

  1. Clone this minimal project: https://github.com/tamagokun/nextjs-expo-router-issue
  2. Run yarn build
  3. See ts error from expo-router
@mauricedoepke
Copy link

Looks like it was just forgotten to get rid of the // @ts-expect-error comment. Maybe you can locally try out if deleting it fixes your issue and the open a pr for that.

@tamagokun
Copy link
Author

tamagokun commented Mar 12, 2023

Trying to appease typescript by changing things inside of expo-router does not work, as it just runs into the next error.

For example, there was a different error that I ran into before the one I posted above, which I tried to fix locally, and it just led to the next one:

../../node_modules/expo-router/src/exports.ts:19:10
Type error: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.

  17 | export { ExpoRoot } from "./ExpoRoot";
  18 | export { Unmatched } from "./views/Unmatched";
> 19 | export { ErrorBoundaryProps } from "./views/Try";
     |          ^
  20 | export { ErrorBoundary } from "./views/ErrorBoundary";

The issue here is that next.js should not be checking types of expo-router in node_modules. This seems to be related to a weird limitation with typescript and how expo-router provides their "types" setting in package.json

The comment I linked to above also links to a typescript issue that further illustrates the problem: #323 (comment)

@tamagokun
Copy link
Author

Looks like this PR fixes the issue: #372

@tamagokun
Copy link
Author

i've confirmed this is fixed in 1.3.0 🎉

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