Snapcraft "Failed to run 'npm ls --global --json' for 'node': Exited with code 1"

Snapcraft build failing with the following error.

Failed to run ‘npm ls --global --json’ for ‘node’: Exited with code 1.

Below is some more error information after I enabled the debug output to the snapcraft command. I’ve tried removing the versions from the modules, different version of nodejs as well as commenting out the build-packages section since the error seems to indicate python as part of the problem.

Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/snapcraft/internal/common.py”, line 73, in _run
return runner(["/bin/sh"], stdin=run_file, **kwargs)
File “/usr/lib/python3.5/subprocess.py”, line 626, in check_output
**kwargs).stdout
File “/usr/lib/python3.5/subprocess.py”, line 708, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command ‘[’/bin/sh’]’ returned non-zero exit status 1

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/snapcraft/_baseplugin.py”, line 221, in run_output
return common.run_output(cmd, cwd=cwd, **kwargs)
File “/usr/lib/python3/dist-packages/snapcraft/internal/common.py”, line 85, in run_output
output = _run(cmd, subprocess.check_output, **kwargs)
File “/usr/lib/python3/dist-packages/snapcraft/internal/common.py”, line 77, in _run
) from call_error
snapcraft.internal.errors.SnapcraftCommandError: Failed to run ‘npm ls --global --json’: Exited with code 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/usr/bin/snapcraft”, line 9, in
load_entry_point(‘snapcraft===2.43.1ubuntu1’, ‘console_scripts’, ‘snapcraft’)()
File “/usr/lib/python3/dist-packages/click/core.py”, line 716, in call
return self.main(*args, **kwargs)
File “/usr/lib/python3/dist-packages/click/core.py”, line 696, in main
rv = self.invoke(ctx)
File “/usr/lib/python3/dist-packages/click/core.py”, line 1037, in invoke
return Command.invoke(self, ctx)
File “/usr/lib/python3/dist-packages/click/core.py”, line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/usr/lib/python3/dist-packages/click/core.py”, line 534, in invoke
return callback(*args, **kwargs)
File “/usr/lib/python3/dist-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/usr/lib/python3/dist-packages/snapcraft/cli/_runner.py”, line 93, in run
ctx.forward(lifecyclecli.commands[“snap”])
File “/usr/lib/python3/dist-packages/click/core.py”, line 552, in forward
return self.invoke(cmd, **kwargs)
File “/usr/lib/python3/dist-packages/click/core.py”, line 534, in invoke
return callback(*args, **kwargs)
File “/usr/lib/python3/dist-packages/snapcraft/cli/lifecycle.py”, line 136, in snap
project = _execute(steps.PRIME, parts=[], **kwargs)
File “/usr/lib/python3/dist-packages/snapcraft/cli/lifecycle.py”, line 35, in _execute
lifecycle.execute(step, project_config, parts)
File “/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py”, line 90, in execute
executor.run(step, part_names)
File “/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py”, line 194, in run
self._handle_step(part_names, part, step, current_step, cli_config)
File “/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py”, line 208, in _handle_step
getattr(self, “run{}”.format(current_step.name))(part)
File “/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py”, line 250, in _run_pull
self._run_step(step=steps.PULL, part=part, progress=“Pulling”)
File “/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py”, line 327, in _run_step
getattr(part, step.name)()
File “/usr/lib/python3/dist-packages/snapcraft/internal/pluginhandler/init.py”, line 415, in pull
self._runner.pull()
File “/usr/lib/python3/dist-packages/snapcraft/internal/pluginhandler/_runner.py”, line 83, in pull
“override-pull”, self._override_pull_scriptlet, self._sourcedir
File “/usr/lib/python3/dist-packages/snapcraft/internal/pluginhandler/_runner.py”, line 162, in _run_scriptlet
scriptlet_name, function_call.strip()
File “/usr/lib/python3/dist-packages/snapcraft/internal/pluginhandler/_runner.py”, line 218, in _handle_builtin_function
function(**function_args)
File “/usr/lib/python3/dist-packages/snapcraft/internal/pluginhandler/init.py”, line 435, in _do_pull
self.plugin.pull()
File “/usr/lib/python3/dist-packages/snapcraft/plugins/nodejs.py”, line 158, in pull
self._npm_install(rootdir=self.sourcedir)
File “/usr/lib/python3/dist-packages/snapcraft/plugins/nodejs.py”, line 202, in _npm_install
return self._get_installed_node_packages(“npm”, self.installdir)
File “/usr/lib/python3/dist-packages/snapcraft/plugins/nodejs.py”, line 260, in _get_installed_node_packages
[package_manager, “ls”, “–global”, “–json”], cwd=cwd
File “/usr/lib/python3/dist-packages/snapcraft/_baseplugin.py”, line 225, in run_output
) from process_error
snapcraft.internal.errors.SnapcraftPluginCommandError: Failed to run ‘npm ls --global --json’ for ‘node’: Exited with code 1.
Verify that the part is using the correct parameters and try again.

There was a question about the format of the yaml and it seems the posting removed the formatting so here’s a link for the document.

https://www.dropbox.com/s/zs05c9ya61x1f0w/snapcraft.yaml?dl=0

I’ve removed the apps section since this is the only part that’s causing a problem in the build.

Resolved by upgrading snapcraft and yaml