'Nextjs deploy on vercel with yarn workspaces is not working

I'm trying to deploy my NextJs app, which is inside a yarn workspace package on my codebase, but I'm getting a build error. This app has another package inside the workspace as a dependency and it's apparently not getting detected while building.

Locally, it's working fine, so I have no clue about what's happening.

I'm using yarn workspaces

The error:

Failed to compile.
--
21:10:39.177 |  
21:10:39.178 | ./src/pages/api/addUser.ts:3:26
21:10:39.178 | Type error: Cannot find module '@p2pmarket/database' or its corresponding type declarations.
21:10:39.178 |  
21:10:39.178 | 1 \| import { NextApiRequest, NextApiResponse } from "next";
21:10:39.178 | 2 \|
21:10:39.178 | > 3 \| import { database } from "@p2pmarket/database";
21:10:39.179 | \|                          ^
21:10:39.179 | 4 \|
21:10:39.180 | 5 \| export default async (req: NextApiRequest, res: NextApiResponse) => {
21:10:39.180 | 6 \|     const user = await database.user.create({});
21:10:39.202 | error Command failed with exit code 1.
21:10:39.203 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
21:10:39.216 | Error: Command "yarn run build" exited with 1

My next.config.js

/**
 * @type {import('next').NextConfig}
 */
const nextConfig = {
    /* config options here */
    swcMinify: true,
    reactStrictMode: false,
    experimental: {
        externalDir: true,
    },
};

module.exports = nextConfig;

My root directory is correctly configured: image

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source