"bench init version-13" failing on Ubuntu 22.04 because of deprecated node-sass?

admin@erpls:~$ bench init frappe-bench --frappe-branch version-13
Setting Up Environment
$ python3 -m venv env
$ /home/admin/frappe-bench/env/bin/python -m pip install --quiet --upgrade pip
Getting frappe
$ git clone https://github.com/frappe/frappe.git --branch version-13 --depth 1 --origin upstream
Cloning into 'frappe'...
remote: Enumerating objects: 2996, done.
remote: Counting objects: 100% (2996/2996), done.
remote: Compressing objects: 100% (2678/2678), done.
remote: Total 2996 (delta 433), reused 1132 (delta 246), pack-reused 0
Receiving objects: 100% (2996/2996), 16.35 MiB | 10.69 MiB/s, done.
Resolving deltas: 100% (433/433), done.
Installing frappe
$ /home/admin/frappe-bench/env/bin/python -m pip install --quiet --upgrade -e /home/admin/frappe-bench/apps/frappe 
$ yarn install
yarn install v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning " > bootstrap@4.5.0" has unmet peer dependency "popper.js@^1.16.0".
warning Workspaces can only be enabled in private projects.
[4/4] Building fresh packages...
[1/3] ⡀ node-sass
[-/3] ⢀ waiting...
error /home/admin/frappe-bench/apps/frappe/node_modules/node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments: 
Directory: /home/admin/frappe-bench/apps/frappe/node_modules/node-sass
Output:
Building: /usr/bin/node /home/admin/frappe-bench/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/bin/node',
gyp verb cli   '/home/admin/frappe-bench/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@16.16.0 | linux | 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 "/usr/bin/python3" in the PATH
gyp verb `which` succeeded /usr/bin/python3 /usr/bin/python3
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /usr/bin/python3 -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: Missing parentheses in call to 'print'. Did you mean print(...)?
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (node:child_process:398:12)
gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
gyp ERR! stack     at maybeClose (node:internal/child_process:1092:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
gyp ERR! System Linux 5.15.0-43-generic
gyp ERR! command "/usr/bin/node" "/home/admin/frappe-bench-ERPLS/apps/frappe/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /home/admin/frappe-bench-ERPLS/apps/frappe/node_modules/node-sass
gyp ERR! node -v v16.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/bench/commands/make.py", line 68, in init
    init(
  File "/usr/local/lib/python3.10/dist-packages/bench/utils/render.py", line 105, in wrapper_fn
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bench/utils/system.py", line 79, in init
    get_app(
  File "/usr/local/lib/python3.10/dist-packages/bench/app.py", line 432, in get_app
    app.install(verbose=verbose, skip_assets=skip_assets, restart_bench=restart_bench)
  File "/usr/local/lib/python3.10/dist-packages/bench/utils/render.py", line 126, in wrapper_fn
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bench/app.py", line 230, in install
    install_app(
  File "/usr/local/lib/python3.10/dist-packages/bench/app.py", line 569, in install_app
    bench.run("yarn install", cwd=app_path)
  File "/usr/local/lib/python3.10/dist-packages/bench/bench.py", line 47, in run
    return exec_cmd(cmd, cwd=cwd or self.cwd)
  File "/usr/local/lib/python3.10/dist-packages/bench/utils/__init__.py", line 155, in exec_cmd
    raise CommandFailedError
bench.exceptions.CommandFailedError
ERROR: There was a problem while creating frappe-bench-ERPLS

Please pardon the very long stack trace.

This is from a proven installation script I am trying for the first time on Ubuntu Jammy (22.04)

The error is pretty obvious:

  • node-gyp is trying to use a Python 2 print statement
  • Ubuntu Jammy no longer supports Python 2

I searched the frappe installed Node modules and found that

  • node-gyp version is v3.8.0
  • the only node-gyp@3.8.0 dependency is from node-sass@4.14.1

According to https://www.npmjs.com/package/node-gyp the latest version is 9.1.0!

According to https://www.npmjs.com/package/node-sass the latest version is 7.0.1!

According to Release v5.0.0 · sass/node-sass · GitHub and node-sass/package.json at v5.0.0 · sass/node-sass · GitHub node-sass@5.0.0 is the first to use node-gyp@7.0.1!

node-sass is deprecated but still maintained.

Any suggestions (apart from reverting to Ubuntu 20.04)?

Update 2022/08/07: I did revert, and I’m having the same problem in Ubuntu 20.04

to use node-gyp < 5, try installing python2

In my .bash_history of a machine I upgraded to 22.04 with ERPNext 13 I have:

nvm install 16 --reinstall-packages-from=current
bench build
npm install sass

resulting in

NAME | DESCRIPTION | AUTHOR | DATE | VERSION |
node-gyp | Node.js native… | =rvagg… | 2022-07-14 | 9.1.0

node-sass | Wrapper around… | =saperski… | 2021-12-27 | 7.0.1

From npm search

FWIW

Hi! Thanks for the suggestion.

It’s not really available to me for a couple of reasons:

  1. I’m not using nvm
  2. bench build only works after bench init succeeds.

In my case bench init is the failing operation.

When I get a chance I will try installing sass with …

sudo npm install -g sass

… again.

I tried earlier and it showed a result: “sass@1.7.2” (I think, it was). Expecting “node-sass@7.0.1”, I assumed that that was totally wrong, but did not check its node_modules hierarchy.

How did you get that report?

NAME | DESCRIPTION | AUTHOR | DATE | VERSION |
node-gyp | Node.js native… | =rvagg… | 2022-07-14 | 9.1.0
node-sass | Wrapper around… | =saperski… | 2021-12-27 | 7.0.1

From: npm search node-sass , npm search node-gyp.

HTH

Also, I went ahead and got python3.10 set up , these posts were helpful:

In preparation of an eventual upgrade to v14.

Hi again, and thanks yet again. It seems you always have the answers I need, even early on a Sunday morning. Wow!

Installing Python2 in 22.04 and backing Node down from 18 to version 14 got me past that problem. Now i cannot install numpy. :roll_eyes: