Hi, I am using npm workspaces and turborepo for a web app, which is reliant on a TypeScript Node.js library which I have defined as an internal package in my monorepo.
When I deploy to Vercel, I get this error: my-app:build: Module not found: Can't resolve '@repo/script.js'
.
Here’s what the package.json for the script looks like:
{
"name": "@repo/script",
"version": "1.0.0",
"description": "",
"scripts": {
"build": "npm i && tsc;",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": { /* some npm registry dependencies */ }
"exports": {
"./*": "./dist/src/*"
}
}
and it’s tsconfig:
{
"compilerOptions": {
"target": "ES2022",
"module": "nodenext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
"composite": true,
"outDir": "./dist",
"rootDir": ".",
"preserveSymlinks": true,
},
"include": ["src"],
"exclude": ["dist", "node_modules"],
"ts-node": {
"require": ["tsconfig-paths/register"]
},
}
My Next.js app’s package.json looks like:
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"check-types": "tsc --noEmit"
},
"dependencies": {
"@radix-ui/react-avatar": "^1.1.0",
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.427.0",
"next": "14.2.5",
"next-themes": "^0.3.0",
"react": "^18",
"react-dom": "^18",
"tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
}
and it’s tsconfig
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"moduleDetection": "force",
"noUncheckedIndexedAccess": true,
"target": "ES2022",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "nodenext",
"moduleResolution": "nodenext",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"preserveSymlinks": true,
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"rootDir": ".",
"paths": {
"@/*": ["./src/*"],
"@repo/script": ["../../lib/script/dist/src/*"],
},
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"],
"references": [
{ "path": "../../lib/script" }
]
}
I’ve tried including @repo/script as a direct dependency of nextjs-app, but that leads to an error as Vercel thinks it’s in the npm registry and tries to fetch it without success. I’ve also tried including a preinstall command which builds @repo/script, but that also doesn’t work.
Am I just misunderstanding how to use a monorepo with Next.js? I’ve looked at the Turborepo examples and they don’t seem to be doing anything different.