Can't import googleapis package in Code: ERROR: Cannot find module 'googleapis' [line 1]

Describe the problem/error/question

I need to download a Google Drive sheet in XLSX format. Currently the GDrive download node only supports ODS format.
I’m trying to download with my own code, but I can’t import googleapis package.
I’ve set environment variables properly to be the most permissive possible:
NODE_FUNCTION_ALLOW_BUILTIN=*
NODE_FUNCTION_ALLOW_EXTERNAL=googleapis

What is the error message (if any)?

ERROR: Cannot find module ‘googleapis’ [line 1]

Please share your workflow

Share the output returned by the last node

VMError: Cannot find module 'googleapis'
    at LegacyResolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:126:9)
    at LegacyResolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:316:16)
    at LegacyResolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver-compat.js:147:17)
    at LegacyResolver.resolve (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:121:15)
    at resolve (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/nodevm.js:317:21)
    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:485:11)
    at requireImpl (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/setup-node-sandbox.js:90:19)
    at require (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/setup-node-sandbox.js:171:10)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:1:117
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:33:2

Information on your n8n setup

  • **n8n version:**1.15.2
  • **Database (default: SQLite):**Postgres
  • **n8n EXECUTIONS_PROCESS setting (default: own, main):**default
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):**Docker
  • **Operating system:**Ubuntu 20

Hey @lero,

Have you added the googleapis package to your docker image? It is the only thing I can think of that could be missing.

If you mean by that doing a “npm install googleapis” inside the container, I did it.
But I’m not sure if I did in the right place. I’ve tried doing it inside /usr/local/lib/node_modules/n8n but I get an permission error

/usr/local/lib/node_modules/n8n $ npm install googleapis
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/n8n/node_modules/minifaker/node_modules/@types/uuid
npm ERR! dest /usr/local/lib/node_modules/n8n/node_modules/minifaker/node_modules/@types/.uuid-bjYIlczr
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/n8n/node_modules/minifaker/node_modules/@types/uuid' -> '/usr/local/lib/node_modules/n8n/node_modules/minifaker/node_modules/@types/.uuid-bjYIlczr'
npm ERR!  [Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/n8n/node_modules/minifaker/node_modules/@types/uuid' -> '/usr/local/lib/node_modules/n8n/node_modules/minifaker/node_modules/@types/.uuid-bjYIlczr'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/usr/local/lib/node_modules/n8n/node_modules/minifaker/node_modules/@types/uuid',
npm ERR!   dest: '/usr/local/lib/node_modules/n8n/node_modules/minifaker/node_modules/@types/.uuid-bjYIlczr'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

Hey @lero,

Normally the best option would be to create your own docker image with the module installed but if you access the container as root and run npm install -g googleapis it may work until you update.