1
votes

I am trying to deploy my functions on the cloud functions emulator but my terminal throws me this error:

$ functions deploy sendNotifications --trigger-http

{ Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@google-cloud/functions-emulator/logs' at Error (native) at Object.fs.mkdirSync (fs.js:922:18) at Object.assertLogsPath (/usr/local/lib/node_modules/@google-cloud/functions-emulator/src/emulator/logs.js:31:10) at new Controller (/usr/local/lib/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:84:32) at Object.exports.handler (/usr/local/lib/node_modules/@google-cloud/functions-emulator/src/cli/commands/deploy.js:124:22) at Object.self.runCommand (/usr/local/lib/node_modules/@google-cloud/functions-emulator/node_modules/yargs/lib/command.js:231:22) at Object.Yargs.self._parseArgs (/usr/local/lib/node_modules/@google-cloud/functions-emulator/node_modules/yargs/yargs.js:989:30) at Object.Yargs.self.parse (/usr/local/lib/node_modules/@google-cloud/functions-emulator/node_modules/yargs/yargs.js:533:23) at Object.main (/usr/local/lib/node_modules/@google-cloud/functions-emulator/src/cli/main.js:69:6) at getProjectId.then (/usr/local/lib/node_modules/@google-cloud/functions-emulator/bin/functions:100:27) errno: -13, code: 'EACCES', syscall: 'mkdir', path: '/usr/local/lib/node_modules/@google-cloud/functions-emulator/logs' }

I have cd-ed to the functions directory and checked that I am logged in to firebase and selected the right project Id. Am i doing something wrongly?

3
as per your personal error - try to run the command with sudo (if you're on linux) of from Administrator cmd (if you're on Win) - xSAVIKx

3 Answers

2
votes

Overview

The proper way to fix this is by changing the npm global directory to one that does not require root permission to install and run.

You really should not be requiring sudo to npm install -g. Likewise to functions start.

Cleansing

Given that you have installed functions, presumably using sudo npm install -g @google-cloud/functions-emulator, you now need to first uninstall it equally with sudo: sudo npm uninstall -g @google-cloud/functions-emulator.

Why uninstall it? You currently have functions installed into a directory where root permissions are required to write. It does require write permission to log file as you can see from the error.

I would suggest uninstalling the other npm packages which you may have installed using sudo, except npm. You can find out what you have using sudo npm list -g --depth=0.

Changing npm global directory

I would suggest going with Option 2 described on https://docs.npmjs.com/getting-started/fixing-npm-permissions

Copy pasting solution from link above:

  1. Make a directory for global installations:

    mkdir ~/.npm-global

  2. Configure npm to use the new directory path:

    npm config set prefix '~/.npm-global'

  3. Open or create a ~/.profile file and add this line:

    export PATH=~/.npm-global/bin:$PATH

  4. Back on the command line, update your system variables:

    source ~/.profile

Install global without sudo

Now that your machine has been cleansed and npm global has been configured to a directory that does not require root permissions, you should be able to install and run without sudo.

1
votes

Had the same issue. For me it did not showed the permission log also..The issues is with the permissions. Try to the command with super user.

Step 1. Start the gcloud functions

sudo functions start

Step 2. Deploy the helloworld function which was exported.

sudo functions deploy helloworld --trigger-http
0
votes

This is obviously very late for the original post. Hope this helps other who has the same error in the future.

I had the same issue turn out I hadn't installed that the requirements properly. Any one who steps in here can look at Error: EACCES: permission denied #195.

Main note of this error install all requirements properly.