near / near-workspaces-js

Write tests once, run them both on NEAR TestNet and a controlled NEAR Sandbox local environment
https://near.github.io/near-workspaces-js/
GNU General Public License v3.0
42 stars 21 forks source link

Mac running on M1 Chip is not able to install the package #110

Closed shivamiitgoa closed 2 years ago

shivamiitgoa commented 2 years ago

More details about the error:

(base) shivamkumar@Shivams-MacBook-Pro example % npx near-workspaces-init
Need to install the following packages:
  near-workspaces-init
Ok to proceed? (y) y
npm ERR! code 1
npm ERR! path /Users/shivamkumar/projects/dragon/example/near-workspaces/node_modules/near-sandbox
npm ERR! command failed
npm ERR! command sh -c node ./install.js
npm ERR! /Users/shivamkumar/projects/dragon/example/near-workspaces/node_modules/near-sandbox/dist/getBinary.js:13
npm ERR!     throw new Error(`Unsupported platform: ${type} ${arch}`);
npm ERR!     ^
npm ERR! 
npm ERR! Error: Unsupported platform: Darwin arm64
npm ERR!     at getPlatform (/Users/shivamkumar/projects/dragon/example/near-workspaces/node_modules/near-sandbox/dist/getBinary.js:13:11)
npm ERR!     at AWSUrl (/Users/shivamkumar/projects/dragon/example/near-workspaces/node_modules/near-sandbox/dist/getBinary.js:16:30)
npm ERR!     at getBinary (/Users/shivamkumar/projects/dragon/example/near-workspaces/node_modules/near-sandbox/dist/getBinary.js:27:19)
npm ERR!     at Object.<anonymous> (/Users/shivamkumar/projects/dragon/example/near-workspaces/node_modules/near-sandbox/dist/install.js:4:27)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
npm ERR!     at Module.load (node:internal/modules/cjs/loader:981:32)
npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm ERR!     at Module.require (node:internal/modules/cjs/loader:1005:19)
npm ERR!     at require (node:internal/modules/cjs/helpers:102:18)

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/shivamkumar/.npm/_logs/2022-02-11T14_06_56_244Z-debug.log
ailisp commented 2 years ago

As nearcore has dependencies that doesn't support M1 chip, we can only build nearcore and sandbox (a specially configured version of nearcore) as Darwin x86-64. So we'll need to fix: always download Darwin x86-64 build of sandbox binary. And M1 users will be able to run with rosetta

shivamiitgoa commented 2 years ago

Hey @ailisp

I built the nearcore from the source but still when I am trying to install near-workspaces-ava, I am getting error.

shivamiitgoa commented 2 years ago

The error is same as above

shivamiitgoa commented 2 years ago

I am able to get it working using these steps:

  1. Remove node_modules and yarn.lock
  2. arch -x86_64 zsh This activates the cli in x64 mode
  3. yarn to install dependencies

It worked after this 🎉

shivamiitgoa commented 2 years ago

I am closing this issue.

tifrel commented 2 years ago

@shivamiitgoa Your workaround seems to require a "dirty state" repo, as it didn't work after freshly running npx near-workspaces-init. A reproducible way to get it to install is:

yarn install # this will actually fail
arch -x86_64 zsh -c 'npm install'
# Now it looks like it worked, but AVA wouldn't start until I added the following
npm install ts-node

Several other versions I tried didn't work, specifically I couldn't get it to work with either yarn or npm alone. npm complained about an old-format package-lock.json (which didn't exist when invoking it), but hey, it kind of works.

Edit: I request keeping this open, as the install step works, but it won't run. I'll be presented with

  Contract works

  Rejected promise returned by test. Reason:

  Error {
    message: 'Unsupported platform: Darwin arm64',
  }

  › getPlatform (node_modules/near-sandbox/dist/getBinary.js:13:11)
  › AWSUrl (node_modules/near-sandbox/dist/getBinary.js:16:30)
  › getBinary (node_modules/near-sandbox/dist/getBinary.js:27:19)
  › sandboxBinary (node_modules/near-workspaces/src/internal-utils.ts:17:75)
  › ensureBinary (node_modules/near-workspaces/src/internal-utils.ts:54:37)
  › Function.init (node_modules/near-workspaces/src/container/server.ts:99:38)
  › SandboxRuntime.beforeRun (node_modules/near-workspaces/src/container/runtime.ts:262:39)
  › SandboxRuntime.createRun (node_modules/near-workspaces/src/container/runtime.ts:111:18)
  › Function.create (node_modules/near-workspaces/src/container/runtime.ts:215:21)

I tried running e.g. arch -x86_64 npm test or with a zsh -c squeezed in, but obviously wasn't that successful.

Edit2: A very dirty workaround is to redefine getPlatform in node_modules/near-sandbox/dist/getBinary.js:

function getPlatform() {
    const type = os.type();
    const arch = os.arch();
    if ((type === "Linux" || type === "Darwin") && arch === "x64") {
        return [type, "x86_64"];
    }
    if (type === "Darwin" && arch === "arm64") return [type, "x86_64"];
    throw new Error(`Unsupported platform: ${type} ${arch}`);
}

The tests will however run.