supabase / cli

Supabase CLI. Manage postgres migrations, run Supabase locally, deploy edge functions. Postgres backups. Generating types from your database schema.
https://supabase.com/docs/reference/cli/about
MIT License
954 stars 178 forks source link

Supabase fails to build after it installs on yarn 4 #1769

Open RobSchilderr opened 6 months ago

RobSchilderr commented 6 months ago

Describe the bug When trying to install Supabase using Yarn Berry 4.0.2 on a MacBook Pro with an M3 chip, the build process fails and exits with code 129. The error message states that Supabase must be built because it has never been built before or the last build failed. Additionally, during the installation process, the entire network connection on the laptop becomes unresponsive.

If I disable postinstall scripts with yarn it does install normally.

To Reproduce Steps to reproduce the behavior:

I am using the Tamagui Takeout stack (https://tamagui.dev/takeout). So I guess a lot of people will run into it starting on a fresh new Macbook M3.

Once I got it working when I did yarn cache clean, npm cache clean --forece and deleted all the node_modules. However it keeps failing which is why I decided to open this issue.

Expected behavior Supabase should be installed and postinstalled successfully without causing the network connection to become unresponsive.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context The log file indicates that the postinstall script is trying to download the supabase CLI from https://github.com/supabase/cli/releases/download/v1.99.0/supabase_darwin_arm64.tar.gz and the checksums from https://github.com/supabase/cli/releases/download/v1.99.0/supabase_1.99.0_checksums.txt. However, it doesn't provide any further details about why the build process fails. The logs for the failed build can be found at /private/var/folders/9c/lzt260ms1dj647flwv171fc00000gn/T/xfs-6e918d5d/build.log. Also it happens with other versions, but Takeout starts with 1.99.0 at the moment.

RobSchilderr commented 6 months ago

My current workaround is to manually download the checksum file and modifying the postinstall script to read this file from the local filesystem instead of downloading it. Here are the steps I took:

  1. Manual Download: The checksum file was manually downloaded from the Supabase GitHub releases page at https://github.com/supabase/cli/releases/download/v1.99.0/supabase_1.99.0_checksums.txt (for version 1.99.0) and placed in the node_modules/supabase/bin/ directory in the project.

  2. Script Modification: The fetchAndParseCheckSumFile function in the postinstall.js script was modified to read the checksum file from the local filesystem. This was done using the fs.promises.readFile function to read the file and path.join to construct the path to the file.

Because __dirname is not available in ES modules, we used import.meta.url to get the URL of the current module, and the url.fileURLToPath function to convert this URL into a file path. We then used path.dirname to get the directory name of this file path.

After these changes, the postinstall script was able to read the checksum file from the local filesystem and continue with the installation process without any issues.

Here is the full function:

import { fileURLToPath } from 'url';

const fetchAndParseCheckSumFile = async (packageJson, agent) => {
  const version = packageJson.version;
  const pkgName = packageJson.name;
  const repo = packageJson.repository;

  // Define the local path to the checksum file
  const dirname = path.dirname(fileURLToPath(import.meta.url));
  const localChecksumFilePath = path.join(dirname, '..', 'bin', 'supabase_1.99.0_checksums.txt');

  // Read the checksum file
  console.info("Reading", localChecksumFilePath);
  const checkSumContent = await fs.promises.readFile(localChecksumFilePath, 'utf-8');
  console.log("Checksum file content:", checkSumContent);

  const lines = checkSumContent.split("\n");
  const checksums = {};
  for (const line of lines) {
    const [checksum, packageName] = line.split(/\s+/);
    checksums[packageName] = checksum;
  }

  return checksums;
};

and make sure to download the checksum manually.

Hopefully someone from the Supabase team can look into this and figure out what's wrong with the checksum download. I wonder if it's firewall/networking related stuff beyond my expertise.

jordanpapaleo commented 6 months ago

I am having the same/similar issue. I am not able to reinstall the cli tool at all completely halting my local development.

I used to have it installed and working but did a rm -rf to node_modules the other week. Since then I have not been able to reinstall the cli tools. I have not tried the manual install process listed above by Rob yet.

Describe the bug When trying to install Supabase using npm on a MacBook Pro with an M2 chip, the build process fails and exits with code 1.

npm i --save-dev supabase
npm ERR! code 1
npm ERR! path /Users/.../node_modules/supabase
npm ERR! command failed
npm ERR! command sh -c node scripts/postinstall.js
npm ERR! Downloading https://github.com/supabase/cli/releases/download/v1.127.3/supabase_darwin_arm64.tar.gz
npm ERR! Downloading https://github.com/supabase/cli/releases/download/v1.127.3/supabase_1.127.3_checksums.txt
npm ERR! file:///Users/jordan/Projects/jp/reno-fitness-lab/node_modules/supabase/node_modules/node-fetch/src/index.js:108
npm ERR!                        reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, 'system', error));
npm ERR!                               ^
npm ERR! 
npm ERR! FetchError: request to https://github.com/supabase/cli/releases/download/v1.127.3/supabase_1.127.3_checksums.txt failed, reason: read ECONNRESET
npm ERR!     at ClientRequest.<anonymous> (file:///Users/.../node_modules/supabase/node_modules/node-fetch/src/index.js:108:11)
npm ERR!     at ClientRequest.emit (node:events:513:28)
npm ERR!     at TLSSocket.socketErrorListener (node:_http_client:494:9)
npm ERR!     at TLSSocket.emit (node:events:513:28)
npm ERR!     at emitErrorNT (node:internal/streams/destroy:151:8)
npm ERR!     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
npm ERR!   type: 'system',
npm ERR!   errno: 'ECONNRESET',
npm ERR!   code: 'ECONNRESET',
npm ERR!   erroredSysCall: 'read'
npm ERR! }
npm ERR! 
npm ERR! Node.js v18.17.0

The error message states that Supabase is having a ECONNRESET. Additionally, during the installation process, the entire network connection on the laptop becomes unresponsive.

To Reproduce

I am using the NextJS with Supabase, but I have also tried the install from a fresh npm init directory. I have used 2 different computers (M2 and intel chip). I have fiber at my house with 500Mbps down. I have also tried tethered to my phone.

Steps to reproduce the behavior:

  1. run npm install supabase from the project root
  2. Wait, wait, wait, have meetings disconnect, make joke after about driving through a tunnel

Expected behavior Supabase should be installed and postinstalled successfully without causing the network connection to become unresponsive.

Desktop: OS: macOS (M2 chip) Version of CLI: Unable to install it. Version of Node.js (if applicable): [Please fill this in with your Node.js version] v18.17.0

sweatybridge commented 6 months ago

This could be related to a bug in node-fetch https://github.com/node-fetch/node-fetch/issues/1735. Let me switch the postinstall script to use native fetch.

jordanpapaleo commented 6 months ago

fwiw: I did just try with homebrew and I was able to get access back to the cli

RobSchilderr commented 6 months ago

fwiw: I did just try with homebrew and I was able to get access back to the cli

Yes but if that's no option and you need to use the one in the project, then it's difficult

jordanpapaleo commented 6 months ago

@RobSchilderr Totally agree. Just providing more data to help identify the issue

sweatybridge commented 6 months ago

I created a beta release with one of the suggested fixes. Could you try again with npx supabase@beta help and let me know if it works?

jordanpapaleo commented 6 months ago

Tried it.

✹✭ ᐅ npx supabase@beta help
Need to install the following packages:
  supabase@1.129.1
Ok to proceed? (y) y
✹✭ ᐅ npx supabase@beta help
Need to install the following packages:
  supabase@1.129.1
  Ok to proceed? (y) npm ERR! canceled

The install took a long time. Then appeared to work as there were no errors. But no help was printed out. I tried the command again and was again prompted to install.

RobSchilderr commented 6 months ago

I created a beta release with one of the suggested fixes. Could you try again with npx supabase@beta help and let me know if it works?

It kept hanging for a while and ultimately gave this response:

robschilder@Robs-MacBook-Pro supabase % yarn add supabase@beta help
➤ YN0000: · Yarn 4.0.2
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + help@npm:3.0.2, supabase@npm:1.131.2, bin-links@npm:4.0.3, cmd-shim@npm:6.0.2, data-uri-to-buffer@npm:4.0.1, and 7 more.
➤ YN0000: └ Completed in 1s 165ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ 12 packages were added to the project (+ 1.62 MiB).
➤ YN0000: └ Completed in 0s 964ms
➤ YN0000: ┌ Link step
➤ YN0007: │ supabase@npm:1.131.2 must be built because it never has been before or the last one failed
➤ YN0009: │ supabase@npm:1.131.2 couldn't be built successfully (exit code 1, logs can be found here: /private/var/folders/9c/lzt260ms1dj647flwv171fc00000gn/T/xfs-c333e11e/build.log)
➤ YN0000: └ Completed in 36s 727ms
➤ YN0000: · Failed with errors in 38s 972ms
robschilder@Robs-MacBook-Pro supabase % 

The logs:

# This file contains the result of Yarn building a package (supabase@npm:1.131.2)
# Script name: postinstall

Downloading https://github.com/supabase/cli/releases/download/v1.131.2/supabase_darwin_arm64.tar.gz
Downloading https://github.com/supabase/cli/releases/download/v1.131.2/supabase_1.131.2_checksums.txt
file:///Users/robschilder/Documents/Projects/app/app/node_modules/supabase/node_modules/node-fetch/src/index.js:108
            reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, 'system', error));
                   ^

FetchError: request to https://github.com/supabase/cli/releases/download/v1.131.2/supabase_1.131.2_checksums.txt failed, reason: read ECONNRESET
    at ClientRequest.<anonymous> (file:///Users/robschilder/Documents/Projects/app/app/node_modules/supabase/node_modules/node-fetch/src/index.js:108:11)
    at ClientRequest.emit (node:events:517:28)
    at TLSSocket.socketErrorListener (node:_http_client:501:9)
    at TLSSocket.emit (node:events:517:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  type: 'system',
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  erroredSysCall: 'read'
}

Node.js v18.19.0

Hope this helps you further, really hope this could get solved for all new Macbook users!

RobSchilderr commented 5 months ago

import { fileURLToPath } from 'url';

Did the logs above help you?

sweatybridge commented 5 months ago

I'm still unable to reproduce this error. Could you try the following and let me know if it works?

NODE_OPTIONS=--no-experimental-fetch yarn add supabase@beta help
RobSchilderr commented 5 months ago

I'm still unable to reproduce this error. Could you try the following and let me know if it works?

NODE_OPTIONS=--no-experimental-fetch yarn add supabase@beta help

Yes this seems to work! What did this do?

sweatybridge commented 5 months ago

I believe there are some incompatibilities between node-fetch and native fetch in newer versions of node. Passing in the NODE_OPTIONS env var disables the native fetch so we can continue using node-fetch.

RobSchilderr commented 5 months ago

I believe there are some incompatibilities between node-fetch and native fetch in newer versions of node. Passing in the NODE_OPTIONS env var disables the native fetch so we can continue using node-fetch.

Alright, I'll pay attention to when this issue will be out of the beta release and test it once more!

RobSchilderr commented 5 months ago

I believe there are some incompatibilities between node-fetch and native fetch in newer versions of node. Passing in the NODE_OPTIONS env var disables the native fetch so we can continue using node-fetch.

I still run into this issue, when will it be out of beta?

dytra commented 2 months ago

I'm having the same issue

RobSchilderr commented 2 months ago

I'm having the same issue

Did my temporary solution also work for you? I still have this issue too.

sweatybridge commented 2 months ago
NODE_OPTIONS=--no-experimental-fetch yarn add supabase

I will add the above workaround to our documentation. Changing the fetcher doesn't seem straightforward.

dytra commented 2 months ago

I'm having the same issue

Did my temporary solution also work for you? I still have this issue too.

I've added the NODE_OPTIONS in my .env file and still doesn't work

sweatybridge commented 2 months ago

I've added the NODE_OPTIONS in my .env file and still doesn't work

I'm not sure if yarn supports dotenv natively https://github.com/yarnpkg/berry/issues/4718. May be it's possible to update .yarnrc.yml file as demonstrated in the issue.

Even then, this is a nodejs config and not necessarily something yarn wants to handle. For simplicity, I'd suggest setting the env var before running yarn add command.

You only need to do this once during installation so it's probably fine.

dytra commented 2 months ago

I've added the NODE_OPTIONS in my .env file and still doesn't work

I'm not sure if yarn supports dotenv natively yarnpkg/berry#4718. May be it's possible to update .yarnrc.yml file as demonstrated in the issue.

Even then, this is a nodejs config and not necessarily something yarn wants to handle. For simplicity, I'd suggest setting the env var before running yarn add command.

You only need to do this once during installation so it's probably fine.

ah , I've export NODE_OPTIONS manually and it works, Thankyou

RobSchilderr commented 1 month ago

I've added the NODE_OPTIONS in my .env file and still doesn't work

I'm not sure if yarn supports dotenv natively yarnpkg/berry#4718. May be it's possible to update .yarnrc.yml file as demonstrated in the issue. Even then, this is a nodejs config and not necessarily something yarn wants to handle. For simplicity, I'd suggest setting the env var before running yarn add command. You only need to do this once during installation so it's probably fine.

ah , I've export NODE_OPTIONS manually and it works, Thankyou

What did you do exactly to fix it?

When I run:

NODE_OPTIONS=--no-experimental-fetch yarn install

it keeps hanging on the installation, same issue, all the internet connection is lost.

Then I added: NODE_OPTIONS=--no-experimental-fetch to my env.local and: injectEnvironmentFiles: - .env.local to my .yarnrc.yml

However this still kept me hanging at: "➤ YN0007: │ supabase@npm:1.142.2 must be built because it never has been before or the last one failed"

The only workaround for me that works is replacing the checksum manually but this is cumbersome to do every installation and new users with an M2/M3 chip will be lost.

If anyone from the Supabase team wants to jump on a call to see what's going on, let me know.

LucidNinja commented 1 month ago

I have the same issue using npm or pnpm on Node v.20.12.2. NODE_OPTIONS=--no-experimental-fetch doesn't seem to work when attempting to update the CLI (i.e. NODE_OPTIONS=--no-experimental-fetch pnpm install supabase@latest). However, it works when just installing the current dependencies. (I'm using the Next JS Subscription Starter). Current version of Supabase CLI is 1.169.6 but can't upgrade to newest patch version.