I'm not able to consistently install clasp. I sometimes get these errors:
sudo npm i -g @google/clasp
/usr/local/bin/clasp -> /usr/local/lib/node_modules/@google/clasp/index.js
> [email protected] install /usr/local/lib/node_modules/@google/clasp/node_modules/grpc
> node-pre-gyp install --fallback-to-build --library=static_library
node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v57 ABI, unknown) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@google/clasp/node_modules/grpc/src/node'
gyp WARN EACCES user "root" does not have permission to access the dev dir "/var/root/.node-gyp/8.11.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/@google/clasp/node_modules/grpc/.node-gyp"
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/local/lib/node_modules/@google/clasp/node_modules/grpc/.node-gyp/8.11.2"
...
npm -v
5.6.0
node -v
v8.11.2
sudo npm i -g @google/clasp
/usr/local/bin/clasp -> /usr/local/lib/node_modules/@google/clasp/index.js
+ @google/[email protected]
updated 1 package in 11.211s
sudo npm uninstall -g @google/clasp
This seems to not give the errors:
sudo npm i -g @google/clasp --allow-root
Another option would be to remove grpc, but I believe it is needed with a different npm module.
sudo npm i -g @google/clasp --unsafe-perm
seems to always work too.
However, running clasp gives this error still:
/usr/local/lib/node_modules/@google/clasp/node_modules/grpc/src/grpc_extension.js:45
throw error;
^
Error: The gRPC binary module was not installed. This may be fixed by running "npm rebuild"
Original error: Cannot find module '/usr/local/lib/node_modules/@google/clasp/node_modules/grpc/src/node/extension_binary/node-v57-darwin-x64-unknown/grpc_node.node'
at Object.<anonymous> (/usr/local/lib/node_modules/@google/clasp/node_modules/grpc/src/grpc_extension.js:43:17)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/@google/clasp/node_modules/grpc/src/client_interceptors.js:145:12)
at Module._compile (module.js:652:30)
grpc is connect to protobufjs (which is probably connected to google APIs)
Running sudo npm rebuild in the clasp folder fixes the CLI. Maybe it should be added as a postinstall step.
I think grpc is used for StackDriver logs (@google-cloud/logging):
Error: Cannot find module 'grpc'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/@google/clasp/node_modules/@google-cloud/common-grpc/src/service.js:26:12)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
If this is the case, we should remove @google-cloud/logging in favor of googleapis.
For better installation consistency we should also look into using npm-shrinkwrap as a way to enforce dependencies more strictly.
The recommended use-case for npm-shrinkwrap.json is applications deployed through the publishing process on the registry: for example, daemons and command-line tools intended as global installs or devDependencies.
Ok, I think that I have figured this out:
TLDR; We will continue to use @google-cloud/logging but NOT grpc.
Bunyan vs Winston
Those these both look like great logging libraries, it is not clear that you can use them to read StackDriver logs, just to format and send log entries to StackDriver. Thus we will not use them.
Looking at @google-cloud/logging's dependencies, we see that it doesn't need grpc directly, but there are a couple packages it depends on that need grpc. These are:
@google-cloud/common-grpc see heregoogle-gaxsee here
Now let's take a look at where @google-cloud/logging uses these two packages.
@google-cloud/common-grpc:
logging uses common-grpc for creating and serializing entries.
Neither of which we do (since we just read logs).
google-gax: logging uses google-gax pretty extensively in this file, this file, and this file. Additionally, it looks like google-gax uses grpc pretty extensively in each of these files.
@google-cloud/common-grpc depends on grpc, we don't really depend on @google-cloud/common-grpc because we are not writing or serializing logs. However, it seems like logging pretty heavily depends on google-gax, which definitely depends on grpcSo what does this mean?
@google-cloud/logging, we need grpc because we need google-gax which depends and uses grpc.However, what if we don't actually need `grpc? Let's find out.
mkdir remove-grpc && cd remove-grpcgit clone https://github.com/google/clasp && cd claspcat package.json | grep grpc"grpc": "^1.10.0",sudo npm uninstall --save grpccat package.json | grep grpccode . (to open VSCode, alternatively use whatever editor you like).sudo npm install (installs all packages, notably grpc is not one of them)package-lock.json and ctrl+f grpc (there should be 9 occurrences."grpc": "^1.10.0",) which is listed as a required module for @google-cloud/common-grpc"grpc": "^1.10.0",) which is listed as a required module for google-gaxgrpc itself, which was put in the package-lock.json because it was depended on by other modules.grpc, one in line 32, two in line 34, and one in line 91.sudo npm run build to build clasp (without grpc)clasp login to login and then clasp clone <scriptId>. Make sure that this script has logs (if not, then make a new script and run it a few times, and log to Stackdriver with console.logclasp logs and it'll tell you to set it up with your projectId. Do that.clasp logs and wait a minute or so...DEBUG Sat May 26 2018 10:56:33 GMT-0700 (PDT) myFunction HELLO WORLD
DEBUG Sat May 26 2018 10:56:32 GMT-0700 (PDT) myFunction HELLO WORLD
DEBUG Sat May 26 2018 10:56:32 GMT-0700 (PDT) myFunction HELLO WORLD
DEBUG Sat May 26 2018 10:56:31 GMT-0700 (PDT) myFunction HELLO WORLD
DEBUG Sat May 26 2018 10:56:30 GMT-0700 (PDT) myFunction HELLO WORLD
Cool, it works! Now let's double check to make sure that it doesn't affect anything else.
/src/test.ts file and find and replace all describe.skip with describe.sudo npm run buildnpm run testclasp push, clasp deployments, clasp deploy, clasp version, and clasp versions Other than that they should all pass.So now what? Well, it doesn't seem like we need grpc, but it is kind of an awful process to remove. It'd be nice if there was a better way...
@grant
Thanks for investigating!
I think we shouldn't use any @google-cloud/ libraries. It brings another set of dependencies and is duplicative of the googleapis library. I think those libraries are better for a server environment and not a quick command line interface.
I'd want to explore a solution that uses googleapis and doesn't use @google-cloud/*. If that doesn't work, we can follow the above progress.
Ah, I did not realize googleapis has a logging client. I will check it out and see what we can do. Thanks!