Is this a turborepo issue?
dugan-dev opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues and found nothing that matches
Library version (optional)
6.1.0
Ask a question
I've been using next-safe-action since v3 and think this is a great tool. Please keep up the great work!
I recently migrated to a turborepo mono repo and am using pnpm as the package manager. In VSCode when looking at the safe-action file or the safe actions themselves code and when I try to build I get this error.
vbpay:build: Type error: The inferred type of 'action' cannot be named without a reference to '../../node_modules/next-safe-action/dist/index-7AaVMS6R.mjs'. This is likely not portable. A type annotation is necessary.
nextjs:build:
nextjs:build: 2 | import { createSafeActionClient } from "next-safe-action";
nextjs:build: 3 |
nextjs:build: > 4 | export const action = createSafeActionClient({
nextjs:build: | ^
nextjs:build: 5 | async middleware() {
nextjs:build: 6 | const { userId } = auth();
nextjs:build: 7 | if (userId === null) {
nextjs:build: ELIFECYCLE Command failed with exit code 1.
When I open ../../node_modules/next-safe-action/dist/index-7AaVMS6R.mjs I saw it had an error bc it was importing @decs/typeschema which wasn't installed so i installed that but still getting the same error.
The funny thing is everything works perfectly fine when I run in dev mode. Of course, if I have a type mismatch between my action schema and type im passing in its brutal because of these errors the typing doesn't work for me to know if its a real error or not.
Additional context
I thought maybe it was pnpm issue but I get the same error when using npm as the package manager for the turbo repo mono repo.
Hi @dugan-dev, it could be. Can you please provide a link to a repo with a minimal reproducible example of this issue? Thanks!
@TheEdoRan As requested here a link to a repo with the issue.
Sorry for the delay and thank you for providing a reproduction link. This is a very tricky one, and I still have to find a way to properly solve it. This problem affects multiple projects, and I am unsure if in this case it's caused by tsup bundling, a TypeScript config, or simply using pnpm in a monorepo. It's related (at least) to these TypeScript issues, and a number of others in multiple repos:
- microsoft/TypeScript#47663
- microsoft/TypeScript#48212
- microsoft/TypeScript#42873
- microsoft/TypeScript#29808
As a workaround, suggested by some users, setting these two options in tsconfig.json
seem to work, but it's certainly not that great of a solution, and if you need to emit declaration files when building the project you can't use them. Anyways, here they are:
{
"compilerOptions": {
"declaration": false,
"declarationMap": false,
}
}
Let me know if this works for you as well, thanks.
@TheEdoRan This solved my problem. Thank you so much!
Getting same error in Vercel:
![image](https://private-user-images.githubusercontent.com/6391776/333816400-9a267e41-b67a-4164-a851-7b24aa70f0f9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE2MDEyOTYsIm5iZiI6MTcyMTYwMDk5NiwicGF0aCI6Ii82MzkxNzc2LzMzMzgxNjQwMC05YTI2N2U0MS1iNjdhLTQxNjQtYTg1MS03YjI0YWE3MGYwZjkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjFUMjIyOTU2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NGI3Yzk4OWZkM2NlODRhYjk0MmVhOGU1YzkxYjJiYzYxYjAxODBlNTkyNjhhYzA2MGM1MDlkNWM1OWNiYmRkOSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.3WanxiKAv_0q2KI80mNw--edX86EapwbJKy0JFYtaxs)
Solution with
{
"compilerOptions": {
"declaration": false,
"declarationMap": false,
}
}
Does not work, tsconfig: https://github.com/kuskusapp/kuskus/blob/main/tsconfig.json