I use snap for install node on Ubuntu 19.04. This causes a problem that I found only when debugging because the error message leads to a false way.
This issue concerns node.js and there the question has already been raised and left unanswered (https://github.com/nodesource/distributions/issues/663). It is necessary providing a true error message to save time for those who have this problem.
$ vsce package
ERROR The specified icon 'extension/icon.png' wasn't found in the extension.
Below code is never called.
Call child_process.exec("only snap package") returns stdout and stderr as empty strings without error.
https://github.com/microsoft/vscode-vsce/blob/f4a3d0d356fabe1128b35643c3aa9b06083c9dae/src/npm.ts#L55-L61
Call collectAllFiles() returns empty array.
https://github.com/microsoft/vscode-vsce/blob/f4a3d0d356fabe1128b35643c3aa9b06083c9dae/src/package.ts#L722-L733
Call processor.onFile() will not happen.
https://github.com/microsoft/vscode-vsce/blob/f4a3d0d356fabe1128b35643c3aa9b06083c9dae/src/package.ts#L761
Similar issue #233.
I encountered the same issue ... The Snap version of NodeJS does not output the stdout when the following commands are used
cp.exec("npm....
cp.exec("node....
cp.exec("yarn....
Thus I managed to find a workaround by redirecting the output via echo (attached patch below). However this workaround is not compatible with other systems and operating systems.
diff --git a/src/npm.ts b/src/npm.ts
index 6137a3c..456c111 100644
--- a/src/npm.ts
+++ b/src/npm.ts
@@ -23,7 +23,8 @@ function exec(command: string, options: IOptions = {}, cancellationToken?: Cance
return new Promise((c, e) => {
let disposeCancellationListener: Function = null;
- const child = cp.exec(command, { ...options, encoding: 'utf8' } as any, (err, stdout: string, stderr: string) => {
+ // Added echo as a workaround for snap nodejs support
+ const child = cp.exec(`echo $(${command})`, { ...options, encoding: 'utf8' } as any, (err, stdout: string, stderr: string) => {
if (disposeCancellationListener) {
disposeCancellationListener();
disposeCancellationListener = null;
I agree that a proper error message should be thrown for such scenarios since The specified icon 'extension/icon.png' wasn't found in the extension. is very misleading.
It might make sense to throw an exception when stdout is empty. (something like the patch below) Looks like all the commands are expecting some kind of response and they are having side-effects when the response is empty. What do you think @joaomoreno? I am ready to create a PR if you think it makes sense.
diff --git a/src/npm.ts b/src/npm.ts
index 71649a4..d71364e 100644
--- a/src/npm.ts
+++ b/src/npm.ts
@@ -30,6 +30,8 @@ function exec(command: string, options: IOptions = {}, cancellationToken?: Cance
}
if (err) { return e(err); }
+ if (stdout === '') { return e(`'${command}' did not return any results.`); }
+
c({ stdout, stderr });
});
@xontab
I didn't understood what we have to do. Should I reinstall Node.js without snap?
EDIT: I found a practical solution. For those who have the same problem and just want to use vsce, use the node:12-alpine Docker image, execute /bin/sh in it. In the container's shell, install vsce globally (no need of sudo) and run your commands.
With docker-compose:
# docker-compose.yml
version: '3.7'
services:
node:
image: node:12-alpine
volumes:
- ".:/work"
… then run: docker-compose run node /bin/sh
In the container's shell:
npm install -g vsce
cd /work
vsce package
Yes, the Snap version does not support the child_process properly and thus an alternative packaging system needs to be used. Using Docker is even better :) Maybe we should build a vsce docker image to avoid these dependency issues.
Most helpful comment
Yes, the Snap version does not support the child_process properly and thus an alternative packaging system needs to be used. Using Docker is even better :) Maybe we should build a vsce docker image to avoid these dependency issues.