Next.js: Deploy with Yarn Workspaces isn't working

Created on 28 Feb 2020  路  16Comments  路  Source: vercel/next.js

Bug report

Describe the bug

I'm trying to deploy a project with yarn workspaces to ZEIT Now. I'm getting an error message that the module I'm trying to import from another package isn't found. To make sure it wasn't my configuration I've tried to deploy the example project as well.

To Reproduce

  1. Go to https://github.com/zeit/next.js/tree/master/examples/with-yarn-workspaces
  2. Pull the repo
  3. Deploy to ZEIT Now
  4. See error
Downloading 3 deployment files...
Installing build runtime...
Build runtime installed: 450.471ms
Looking up build cache...
Build cache not found
Installing dependencies...
yarn install v1.22.0
info No lockfile found.
[1/4] Resolving packages...
warning next > @babel/runtime-corejs2 > [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
warning next > styled-jsx > babel-types > babel-runtime > [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 11.84s.
Running "yarn run build"
yarn run v1.22.0
$ next build
Creating an optimized production build...
Attention: Next.js now collects completely anonymous telemetry regarding usage.
This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://nextjs.org/telemetry
Failed to compile.
./pages/index.js
Module not found: Can't resolve 'bar' in '/zeit/2a0c03f8/pages'
> Build error occurred
Error: > Build failed because of webpack errors
    at build (/zeit/2a0c03f8/node_modules/next/dist/build/index.js:12:900)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Exited with 1
    at ChildProcess.<anonymous> (/zeit/5b4460ddbc71b64d/.build-utils/.builder/node_modules/@now/next/dist/index.js:47170:24)
    at ChildProcess.emit (events.js:223:5)
    at ChildProcess.EventEmitter.emit (domain.js:475:20)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
worker exited with code 20 and signal null
Done with "package.json"

Expected behavior

The project should deploy without errors.

needs investigation

Most helpful comment

Well the problem is that we don't want next specific code/config in the root of the monorepo. I agree it works but it clutters the codebase for the developers that have nothing to do with this part of the codebase.

All 16 comments

Can confirm. This is an issue right now.

@androbwebb @tomhoogenboom I figured out a workaround for this. You can look at the open PR to see how I got it working and deployed with Zeit.

Deployed example: https://next-js-with-yarn-workspaces-9v8nodujr.now.sh/
Repo: https://github.com/special-character/next-js-with-yarn-workspaces

@special-character Thanks. This is a workaround indeed but it's not a solution. The project I'm trying to deploy on zeit is a monorepo that basically has three modules: A react native one, one for shared code and a next.js project.

Once I lift the next.js config to the root of the repo I'm not using it as yarn workspaces anymore but I'm just defining aliases for subfolders in the config.
This comes with an extra problem that I know need to make sure the postinstall scripts in my native module don't get executed.

So thanks for the effort but I hope someone from Zeit can look into this.

@tomhoogenboom did you find any solution for this?

I'm having this problem also. I have a monorepo using workspace with three packages: shared, nextjs app and react native app. Zeit is failing because it's trying to install the shared package from the registry and not from the local packages.

No there's currently no solution for this. I did get a reply from Kevin at Zeit and he told me it is on their radar.

Any movement on this? I'm encountering this issue too...

@tomhoogenboom I don't see how this doesn't work for you. This repo deploys the web project and the web project imports from both local modules. Sure, it isn't a perfect solution but it is using workspaces and it is building next. The example is deployed https://next-js-with-yarn-workspaces.now.sh/

It at least works for me! Maybe your use case is more complicated

Well the problem is that we don't want next specific code/config in the root of the monorepo. I agree it works but it clutters the codebase for the developers that have nothing to do with this part of the codebase.

@androbwebb @tomhoogenboom I figured out a workaround for this. You can look at the open PR to see how I got it working and deployed with Zeit.

Deployed example: https://next-js-with-yarn-workspaces-9v8nodujr.now.sh/
Repo: https://github.com/special-character/next-js-with-yarn-workspaces

thanks for the workaround.
it work for me as well.

looking forward for a new solution from zeit team.

I agree with @tomhoogenboom, I don't think that moving the next.config.js to the root folder is the solution. When you have a monorepo, you usually want to have each app isolated from each other.

Yeah, having similar issues.

I'm still experiencing this. How was this actually fixed?

Facing same issue ? There is a fix ?

This seems still to be an issue with a workaround that is less than ideal. I would be interested in looking into this issue. Can this be reopened?

Vercel now supports monorepo so that shouldn't be an issue anymore. You can read more here: https://vercel.com/blog/monorepos

Was this page helpful?
0 / 5 - 0 ratings