blitz-js / legacy-framework

MIT License
3 stars 2 forks source link

Error when using Blitz and Turborepo #366

Closed kevinlangleyjr closed 2 years ago

kevinlangleyjr commented 2 years ago

What is the problem?

When trying to spin up a Blitz app within a Turborepo monorepo, I keep getting the same error:

UnhandledPromiseRejectionWarning: TypeError: (0 , utils_1.getProjectRoot) is not a function

I have a sample repo located here that reproduces the error.

Paste all your error logs here:

blitz-app:dev: $ blitz dev
blitz-app:dev: Loaded env from /Users/klangley/Development/Active/turborepo-blitz/apps/blitz-app/.env.local
blitz-app:dev: Loaded env from /Users/klangley/Development/Active/turborepo-blitz/apps/blitz-app/.env
blitz-app:dev: (node:93726) UnhandledPromiseRejectionWarning: TypeError: (0 , utils_1.getProjectRoot) is not a function
blitz-app:dev:     at /Users/klangley/Development/Active/turborepo-blitz/node_modules/@blitzjs/cli/lib/src/index.js:27:84
blitz-app:dev:     at Generator.next (<anonymous>)
blitz-app:dev:     at /Users/klangley/Development/Active/turborepo-blitz/node_modules/tslib/tslib.js:117:75
blitz-app:dev:     at new Promise (<anonymous>)
blitz-app:dev:     at __awaiter (/Users/klangley/Development/Active/turborepo-blitz/node_modules/tslib/tslib.js:113:16)
blitz-app:dev:     at buildConfigIfNeeded (/Users/klangley/Development/Active/turborepo-blitz/node_modules/@blitzjs/cli/lib/src/index.js:23:34)
blitz-app:dev:     at Object.run (/Users/klangley/Development/Active/turborepo-blitz/node_modules/@blitzjs/cli/lib/src/index.js:38:5)
blitz-app:dev:     at main (/Users/klangley/Development/Active/turborepo-blitz/node_modules/blitz/cli/dist/blitz-cli.cjs.dev.js:98:9)
blitz-app:dev:     at Object.<anonymous> (/Users/klangley/Development/Active/turborepo-blitz/node_modules/blitz/cli/dist/blitz-cli.cjs.dev.js:122:1)
blitz-app:dev:     at Module._compile (internal/modules/cjs/loader.js:1085:14)
blitz-app:dev: (Use `node --trace-warnings ...` to show where the warning was created)
blitz-app:dev: (node:93726) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
blitz-app:dev: (node:93726) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Paste all relevant code snippets here:

What are detailed steps to reproduce this?

  1. Spin up new Turborepo
  2. Spin up new Blitz app within ./apps/{name-of-app}
  3. Run yarn dev or npm run dev (depending on which was chosen when setting up Turborepo)
  4. Notice error

Run blitz -v and paste the output here:

Loaded env from /Users/klangley/Development/Active/turborepo-blitz/apps/blitz-app/.env.local
Loaded env from /Users/klangley/Development/Active/turborepo-blitz/apps/blitz-app/.env
macOS Catalina | darwin-x64 | Node: v14.18.2

blitz: 0.44.4 (global)
blitz: 0.44.4 (local)

  Package manager: npm 
  System:
    OS: macOS 10.15.7
    CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
    Memory: 308.75 MB / 16.00 GB
    Shell: 5.8 - /usr/local/bin/zsh
  Binaries:
    Node: 14.18.2 - ~/.nvm/versions/node/v14.18.2/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v14.18.2/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: Not Found
    blitz: Not Found
    prisma: Not Found
    react: 18.0.0-beta-149b420f6-20211119 => 18.0.0-beta-149b420f6-20211119 
    react-dom: 18.0.0-alpha-5ca4b0433-20211020 => 18.0.0-alpha-5ca4b0433-20211020 
    typescript: Not Found

Please include below any other applicable logs and screenshots that show your problem:

No response

beerose commented 2 years ago

Hi, someone recently had this error with a monorepo and yarn3. They solved it by adding this to package.json:

"installConfig": {
    "hoistingLimits": "workspaces"
 }

Could you try that and see if that helps?

The problem is that next dependency wasn't resolved properly — it probably happens because you have other apps that use next and there's only one version installed (and not what Blitz needs).

kevinlangleyjr commented 2 years ago

@beerose, thanks for the fast response!

I tried adding the hoisting limits in my package.json as you suggested. Unfortunately I am still encountering the same exact error with getProjectRoot() being called from buildConfigIfNeeded().

beerose commented 2 years ago

I cloned your repo and modified workspaces config to this in package.json:

  "workspaces": {
    "packages": [
      "apps/*",
      "packages/*"
    ],
    "nohoist": [
      "**/blitz",
      "**/@blitzjs/*",
      "**/next"
    ]
  },

That seems to work now.

kevinlangleyjr commented 2 years ago

That worked perfectly, thank you @beerose!!!