Error: bench setup requirements | yarn install | MacOS Mojave

Getting the error below while executing bench setup requirements.

Updating Python libraries...
INFO:bench.utils:./env/bin/pip install --upgrade pip
Requirement already up-to-date: pip in ./env/lib/python3.7/site-packages (19.1.1)
INFO:bench.utils:./env/bin/pip install -q -r ./apps/siscohealth/requirements.txt
INFO:bench.utils:./env/bin/pip install -q -r ./apps/frappe/requirements.txt
INFO:bench.utils:./env/bin/pip install -q -r ./apps/erpnext/requirements.txt
INFO:bench.utils:./env/bin/pip install -q -r ./apps/frappe_io/requirements.txt
INFO:bench.utils:./env/bin/pip install -q -r ./apps/metabase/requirements.txt
Updating node packages...
INFO:bench.utils:yarn install
yarn install v1.10.1
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning " > bootstrap@4.3.1" has unmet peer dependency "jquery@1.9.1 - 3".
warning " > bootstrap@4.3.1" has unmet peer dependency "popper.js@^1.14.7".
[4/4] 📃  Building fresh packages...
[1/2] ⡀ cypress
error /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments: 
Directory: /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/node-sass
Output:
Building: /usr/local/Cellar/node/12.3.1/bin/node /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   '/usr/local/Cellar/node/12.3.1/bin/node',
gyp verb cli   '/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library='
gyp verb cli ]
gyp info using node-gyp@3.8.0
gyp info using node@12.3.1 | darwin | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:89:16
gyp verb `which` failed     at /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:149:21)
gyp verb `which` failed  python2 Error: not found: python2
gyp verb `which` failed     at getNotFoundError (/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:89:16
gyp verb `which` failed     at /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:149:21) {
gyp verb `which` failed   stack: 'Error: not found: python2\n    at getNotFoundError ' +
gyp verb `which` failed     '(/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:13:12)\n' +
gyp verb `which` failed     '    at F ' +
gyp verb `which` failed     '(/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:68:19)\n' +
gyp verb `which` failed     '    at E ' +
gyp verb `which` failed     '(/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:80:29)\n' +
gyp verb `which` failed     '    at ' +
gyp verb `which` failed     '/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:89:16\n' +
gyp verb `which` failed     '    at ' +
gyp verb `which` failed     '/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/isexe/index.js:42:5\n' +
gyp verb `which` failed     '    at ' +
gyp verb `which` failed     '/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/isexe/mode.js:8:5\n' +
gyp verb `which` failed     '    at FSReqCallback.oncomplete (fs.js:149:21)',
gyp verb `which` failed   code: 'ENOENT'
gyp verb `which` failed }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python /Users/navdeepghai/navdeep/develop/env/bin/python
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /Users/navdeepghai/navdeep/develop/env/bin/python -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:294:12)
gyp ERR! stack     at ChildProcess.emit (events.js:200:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
gyp ERR! stack     at Socket.<anonymous> (internal/child_process.js:430:11)
gyp ERR! stack     at Socket.emit (events.js:200:13)
gyp ERR! stack     at Pipe.<anonymous> (net.js:586:12)
gyp ERR! System Darwin 18.6.0
gyp ERR! command "/usr/local/Cellar/node/12.3.1/bin/node" "/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/node-sass
gyp ERR! node -v v12.3.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
Build failed with error code: 1
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this 
Traceback (most recent call last):
  File "/Users/navdeepghai/navdeep/develop/env/bin/bench", line 11, in <module>
    sys.exit(cli())
  File "/Users/navdeepghai/navdeep/develop/env/lib/python3.7/site-packages/bench/cli.py", line 40, in cli
    bench_command()
  File "/Users/navdeepghai/navdeep/develop/env/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/navdeepghai/navdeep/develop/env/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/navdeepghai/navdeep/develop/env/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/navdeepghai/navdeep/develop/env/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/navdeepghai/navdeep/develop/env/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/navdeepghai/navdeep/develop/env/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/navdeepghai/navdeep/develop/env/lib/python3.7/site-packages/bench/commands/setup.py", line 163, in setup_requirements
    setup_node_requirements()
  File "/Users/navdeepghai/navdeep/develop/env/lib/python3.7/site-packages/bench/commands/setup.py", line 171, in setup_node_requirements
    update_node_packages()
  File "/Users/navdeepghai/navdeep/develop/env/lib/python3.7/site-packages/bench/utils.py", line 449, in update_node_packages
    update_yarn_packages(bench_path)
  File "/Users/navdeepghai/navdeep/develop/env/lib/python3.7/site-packages/bench/utils.py", line 462, in update_yarn_packages
    exec_cmd('yarn install', cwd=app_path)
  File "/Users/navdeepghai/navdeep/develop/env/lib/python3.7/site-packages/bench/utils.py", line 159, in exec_cmd
    raise CommandFailedError(cmd)
bench.utils.CommandFailedError: yarn install

I tried manually to execute yarn install and it’s working fine.
Output:

yarn install v1.10.1
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 0.04s.

I also installed the node-sass manually and it’s working fine.

npm install node-sass
npm WARN registry Using stale data from https://registry.npmjs.org/ because the host is inaccessible -- are you offline?
npm WARN registry Using stale data from https://registry.npmjs.org/ due to a request error during revalidation.

> node-sass@4.12.0 install /Users/navdeepghai/navdeep/develop/node_modules/node-sass
> node scripts/install.js

Cached binary found at /Users/navdeepghai/.npm/node-sass/4.12.0/darwin-x64-72_binding.node

> node-sass@4.12.0 postinstall /Users/navdeepghai/navdeep/develop/node_modules/node-sass
> node scripts/build.js

Binary found at /Users/navdeepghai/navdeep/develop/node_modules/node-sass/vendor/darwin-x64-72/binding.node
Testing binary
Binary is fine
npm WARN saveError ENOENT: no such file or directory, open '/Users/navdeepghai/navdeep/develop/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/Users/navdeepghai/navdeep/develop/package.json'
npm WARN develop No description
npm WARN develop No repository field.
npm WARN develop No README data
npm WARN develop No license field.

+ node-sass@4.12.0
updated 1 package in 16.668s

I don’t know why it’s checking python2 path in python3 environment.

gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:89:16
gyp verb `which` failed     at /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:149:21)
gyp verb `which` failed  python2 Error: not found: python2
gyp verb `which` failed     at getNotFoundError (/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:89:16
gyp verb `which` failed     at /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:149:21) {
gyp verb `which` failed   stack: 'Error: not found: python2\n    at getNotFoundError ' +
gyp verb `which` failed     '(/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:13:12)\n' +
gyp verb `which` failed     '    at F ' +
gyp verb `which` failed     '(/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:68:19)\n' +
gyp verb `which` failed     '    at E ' +
gyp verb `which` failed     '(/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:80:29)\n' +
gyp verb `which` failed     '    at ' +
gyp verb `which` failed     '/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/which/which.js:89:16\n' +
gyp verb `which` failed     '    at ' +
gyp verb `which` failed     '/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/isexe/index.js:42:5\n' +
gyp verb `which` failed     '    at ' +
gyp verb `which` failed     '/Users/navdeepghai/navdeep/develop/apps/frappe/node_modules/isexe/mode.js:8:5\n' +
gyp verb `which` failed     '    at FSReqCallback.oncomplete (fs.js:149:21)',
gyp verb `which` failed   code: 'ENOENT'
gyp verb `which` failed }

Bench start logs:

11:10:39 watch.1          | Rebuilding frappe-web.css
11:10:39 watch.1          | Error in: /Users/navdeepghai/navdeep/develop/apps/frappe/frappe/public/scss/website.scss
11:10:39 watch.1          | Error: You need to install either node-sass or sass in order to process Sass files

You seem to be running node version 12, can you downgrade to node version 10 and retry?

On debian, this works (but I don’t know about on Mac)

npm config set prefix ‘~/.npm’
export PATH=~/.npm/bin:$PATH
source ~/.profile
npm install -g yarn
bench update

You also have ENOENT errors - I’m sure you can search for a fix for that

I think there are different ways to fix this problem.

I just removed node_modules folder then package.json file from frappe-bench folder and
execute the bench setup socketio followed by bench setup requirements command.

Now it’s working like charm!
@adityahase, I downgraded and it’s working fine(FYI: but it’s also working fine on v12).
@clarkej Thanks for the hint, I faced this problem because of multi-tenant environment.

Did you mean frappe-bench/apps/frappe folder? Because I see no node_modules and package.json in the main frappe-bench folder!