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

Make sure there is monorepo .vercel/output #1770

Open
pi0 opened this issue Sep 28, 2023 · 7 comments
Open

Make sure there is monorepo .vercel/output #1770

pi0 opened this issue Sep 28, 2023 · 7 comments
Assignees

Comments

@pi0
Copy link
Member

pi0 commented Sep 28, 2023

When Niro builds are from a monorepo subdirectory (as root) like /project/docs/, we do generate /project/docs/.vercel/output but unless Vercel using configured sub-directory as root, tries output config from /project/.vercel/output.

In the past, we have tried to detect monorepo/workspace root and change defaults but it then introduced more edge cases. (references missing)

As an alternative and lighter workaround to this, we might try to create a symbolic link from /project/docs/.vercel/output to /project/.vercel/output to try to automatically resolve this problem.

@pi0 pi0 self-assigned this Sep 28, 2023
@DavidDeSloovere
Copy link
Contributor

I can't figure out how to deploy my /apps/web nuxt project to Vercel. Is this issue the reason why it's not working?

I have /packages/somename and /apps/web. Using pnpm workspaces. Not using nx or turborepo.
Build works fine in Vercel. But when it comes to uploading the output, it fails.

I have tried many of the /.vercel/output or /output variations as custom Output directory in the vercel project settings, but even if files get deployed, it won't run the app and just 404.

While this issue is open, is there any advice on the correct custom Output directory to get the nuxt app running?

@pi0
Copy link
Member Author

pi0 commented Feb 16, 2024

Sadly yes the problem exsits. If you have only one vercel deployment for monorepo, you can make a link with ln -s ./packages/name/.vercel .vercel it might help but haven't tried.

@pi0
Copy link
Member Author

pi0 commented Feb 16, 2024

In the past, we have tried to detect monorepo/workspace root and change defaults but it then introduced more edge cases. (references missing)

@danielroe do you remember the reason btw? :D

@danielroe
Copy link
Member

IIRC, it was because Vercel allow users to pick a subdirectory, and in this case they look for build output within that subdirectory rather than at workspace root.

I wonder if they expose this information at build time in an environment variable? (Or maybe they would be willing to do so?)

@pi0
Copy link
Member Author

pi0 commented Feb 16, 2024

I bet there is already one! Thanks for sharing your thoughts @danielroe ❤️

@DavidDeSloovere
Copy link
Contributor

Thanks for the replies.

Not sure if you can do anything with this, but I ran printenv in my build script. Sorted them, redacted some values.

VERCEL_PROJECT_SETTINGS_OUTPUT_DIRECTORY contains the apps/web/.vercel/output value I set in Vercel settings as 'output directory'. I tried a lot of variations in this one.

I don't change the root directory, ie to the web app, because then other packages higher up the file system can't be accessed.

The apps/web/.vercel/output folder contains these files/folders, after pnpm --recursive build, which isn't enough to run the Nuxt site.
image

I tried ln -s apps/web/.vercel .vercel, and removed my 'output directory', but the default of Vercel for Nuxt project is to look for dist folder. So I tried ln -s apps/web/dist dist. But keep getting this error, even though I can verify the existance with ls -l ./dist.

11:36:40.770 | lrwxrwxrwx 1 root root 15 Feb 18 10:36 ./dist -> ./apps/web/dist
Error: No Output Directory named "dist" found after the Build completed. You can configure the Output Directory in your Project Settings.

Looking at nuxi build in Nuxt docs, there is no option to specify where to output the build. That would eliminate the need for the symlink. Now I think of it, I could also just copy the required output to dist, but that is probably no different than specifying the 'output directory' in Vercel settings.

I will change my repo and work in a different way. If you want me to test something, I'm happy to help.

_=/usr/bin/printenv
__VERCEL_BUILD_RUNNING=1
AWS_EXECUTION_ENV=vercel-hive
CI=1
DD_TAGS=ec2_host:i-0e68ae7101219aa24
DD_TRACE_STARTUP_LOGS=false
ENABLE_VC_BUILD=1
FAKEROOTKEY=yes
HOME=/vercel
INIT_CWD=/vercel/path0
LANG=en_US.UTF-8
NEXT_PRIVATE_MULTI_PAYLOAD=1
NEXT_SHARP_PATH=/usr/local/share/.config/yarn/global/node_modules/sharp
NODE=/node20/bin/node
NODE_OPTIONS=--max_old_space_size=8192
NOW_BUILDER=1
npm_command=run-script
npm_config_frozen_lockfile=
npm_config_node_gyp=/pnpm8/node_modules/pnpm/dist/node_modules/node-gyp/bin/node-gyp.js
npm_config_registry=https://registry.npmjs.org/
npm_config_user_agent=pnpm/8.15.2 npm/? node/v20.11.0 linux x64
npm_execpath=/pnpm8/node_modules/pnpm/bin/pnpm.cjs
npm_lifecycle_event=build
npm_lifecycle_script=redacted
npm_node_execpath=/node20/bin/node
npm_package_engines_node=20.x
npm_package_name=redacted
npm_package_private=true
npm_package_type=module
NUXT_ENV_VERCEL_BRANCH_URL=redacted.vercel.app
NUXT_ENV_VERCEL_ENV=preview
NUXT_ENV_VERCEL_GIT_COMMIT_AUTHOR_LOGIN=DavidDeSloovere
NUXT_ENV_VERCEL_GIT_COMMIT_AUTHOR_NAME=David De Sloovere
NUXT_ENV_VERCEL_GIT_COMMIT_MESSAGE=printenv
NUXT_ENV_VERCEL_GIT_COMMIT_REF=dasl/vercel
NUXT_ENV_VERCEL_GIT_COMMIT_SHA=cb5e1a53306d81192bbe5a209a792ee56e4d3e9d
NUXT_ENV_VERCEL_GIT_PREVIOUS_SHA=
NUXT_ENV_VERCEL_GIT_PROVIDER=github
NUXT_ENV_VERCEL_GIT_PULL_REQUEST_ID=5
NUXT_ENV_VERCEL_GIT_REPO_ID=redacted
NUXT_ENV_VERCEL_GIT_REPO_OWNER=redacted
NUXT_ENV_VERCEL_GIT_REPO_SLUG=redacted
NUXT_ENV_VERCEL_URL=redacted
NX_DAEMON=false
PATH=/vercel/path0/node_modules/.bin:/pnpm8/node_modules/pnpm/dist/node-gyp-bin:/vercel/path0/node_modules/.bin:/vercel/path0/node_modules/.bin:/pnpm8/node_modules/.bin:/vercel/.yarn/bin:/vercel/.config/yarn/global/node_modules/.bin:/node20/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bun1
PNPM_SCRIPT_SRC_DIR=/vercel/path0
PWD=/vercel/path0
SHLVL=1
TURBO_CI_VENDOR_ENV_KEY=NUXT_ENV_VERCEL_
TURBO_REMOTE_ONLY=true
TURBO_RUN_SUMMARY=true
TZ=:UTC
USE_NODE_BRIDGE_LAYER_LATEST=1
USE_OUTPUT_FOR_EDGE_FUNCTIONS=1
VERCEL=1
VERCEL_ALLOW_NODEJS20=1
VERCEL_ALLOW_RUBY32=1
VERCEL_API_BUILD_CONTAINERS_ENDPOINT=https://api-iad1.vercel.com/build-containers
VERCEL_API_BUILD_CONTAINERS_TOKEN=8cc8djSpXqQA9Qj0vBNmdmT6
VERCEL_API_ENDPOINT=https://api-iad1.vercel.com
VERCEL_ARTIFACTS_OWNER=redacted
VERCEL_ARTIFACTS_TOKEN=redacted
VERCEL_BRANCH_URL=redacted.vercel.app
VERCEL_BUILD_MONOREPO_SUPPORT=1
VERCEL_BUILD_OUTPUTS_EDGE_FUNCTION=1
VERCEL_BUILD_PROVIDER=hive
VERCEL_CLUSTER=hvi_iad1_ginger
VERCEL_DEPLOYMENT_ID=redacted
VERCEL_DEPLOYMENT_SKEW_HANDLING=1
VERCEL_DISCOVER_FOLDER_SIZES=1
VERCEL_EDGE_FUNCTIONS_EMBEDDED_SOURCEMAPS=1
VERCEL_EDGE_FUNCTIONS_REGIONAL_INVOCATION=1
VERCEL_EDGE_FUNCTIONS_STRICT_MODE=1
VERCEL_EDGE_OTEL_COLLECTOR=1
VERCEL_EDGE_SUSPENSE_CACHE=1
VERCEL_ENABLE_NODE_COMPATIBILITY=1
VERCEL_ENV=preview
VERCEL_FUNCTION_REGIONS=cdg1
VERCEL_GIT_COMMIT_AUTHOR_LOGIN=DavidDeSloovere
VERCEL_GIT_COMMIT_AUTHOR_NAME=David De Sloovere
VERCEL_GIT_COMMIT_MESSAGE=printenv
VERCEL_GIT_COMMIT_REF=dasl/vercel
VERCEL_GIT_COMMIT_SHA=redacted
VERCEL_GIT_PREVIOUS_SHA=
VERCEL_GIT_PROVIDER=github
VERCEL_GIT_PULL_REQUEST_ID=5
VERCEL_GIT_REPO_ID=redacted
VERCEL_GIT_REPO_OWNER=redacted
VERCEL_GIT_REPO_SLUG=redacted
VERCEL_HIVE_BANDWIDTH=150000000
VERCEL_HIVE_CELL_ID=hvc_1d4d6e9fd9104ce7a002858bdd76
VERCEL_HIVE_ID=hvi_iad1_ginger
VERCEL_HIVE_IOPS=10000
VERCEL_HIVE_VERSION=redacted
VERCEL_IGNORE_BUILD_STEP_PACKAGE_MANAGER_DETECT=1
VERCEL_IMAGE_ID=sha256:e475ce6563103163dcd32a35140ca669fd7648020b12125aa7beb7166190e76c
VERCEL_LAYER_LAUNCHER=1
VERCEL_NEXT_BUNDLED_SERVER=1
VERCEL_ORG_ID=redacted
VERCEL_PROJECT_ID=redacted
VERCEL_PROJECT_SETTINGS_BUILD_COMMAND=pnpm run build
VERCEL_PROJECT_SETTINGS_NODE_VERSION=20.x
VERCEL_PROJECT_SETTINGS_OUTPUT_DIRECTORY=apps/web/.vercel/output
VERCEL_RICHER_DEPLOYMENT_OUTPUTS=1
VERCEL_SERVERLESS_FUNCTION_FAILOVER=1
VERCEL_SERVERLESS_SUSPENSE_CACHE=1
VERCEL_URL=redacted
VERCEL_USE_EDGE_FUNCTIONS_BRIDGE_LATEST=1
VERCEL_USE_NODE_BRIDGE_PRIVATE_LATEST=1
YARN_NODE_LINKER=node-modules

@DavidDeSloovere
Copy link
Contributor

I've got an update on this. Turns out Nuxt / Nitro has no issue with monorepo based on pnpm workspaces.

Important setting: The root directory should point to the Nuxt app. (Vercel auto-detected that and prefilled the path to the Nuxt app!)

The fact that is works when you specify a root directory is actually mentioned in the first comment of this issue.

And I think this is fine. I tried the symlinking and could not get it to work. So there might not be a solution to this issue, when not specifying the the correct root dir that is.

Also, what if you have 2 Nuxt app in the mono repo, which one will you simlink to the root?

There is a working solution, I would suggest that this issue can be closed, maybe with some extra documentation (I will send PR).


image

In the build log you can see the dependency pointing to the right folder.

image


Some more details:

After cloning https://github.com/serkodev/nuxt-monorepo and successfully deploying to Vercel that I started to investigate.

Although my local setup worked fine, using a Nuxt app and a TS lib (using tsup), it did not build on Vercel because Vite had an issue finding the entry of my package as defined in /packages/somelib/package.json.

[error] Nuxt Build Error: [commonjs--resolver] Failed to resolve entry for package "ebs-common". The package may have incorrect main/module/exports specified in its package.json.

I used dist/index.js. I was overthinking it, and wanted to use tsup. I was making it too complex.
Just referencing src/index.ts is actually fine for Vite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants