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

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

Open
RobSchilderr opened this issue Dec 20, 2023 · 21 comments
Open

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

RobSchilderr opened this issue Dec 20, 2023 · 21 comments

Comments

@RobSchilderr
Copy link

RobSchilderr commented Dec 20, 2023

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):

  • OS: macOS (M3 chip)
  • Version of CLI: 1.123.4
  • Version of Node.js (if applicable): [Please fill this in with your Node.js version] v18.19.0
  • Versiion of Yarn: 4.0.2
  • Setup: Turborepo

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
Copy link
Author

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.

@sweatybridge sweatybridge changed the title Supabase fails to build after it installs Supabase fails to build after it installs on yarn 4 Dec 21, 2023
@jordanpapaleo
Copy link

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
Copy link
Contributor

This could be related to a bug in node-fetch node-fetch/node-fetch#1735. Let me switch the postinstall script to use native fetch.

@jordanpapaleo
Copy link

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

@RobSchilderr
Copy link
Author

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
Copy link

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

@sweatybridge
Copy link
Contributor

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
Copy link

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
Copy link
Author

RobSchilderr commented Jan 7, 2024

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
Copy link
Author

import { fileURLToPath } from 'url';

Did the logs above help you?

@sweatybridge
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Author

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
Copy link

dytra commented May 3, 2024

I'm having the same issue

@RobSchilderr
Copy link
Author

I'm having the same issue

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

@sweatybridge
Copy link
Contributor

sweatybridge commented May 3, 2024

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
Copy link

dytra commented May 3, 2024

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
Copy link
Contributor

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.

@dytra
Copy link

dytra commented May 3, 2024

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

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

4 participants