Google-api-nodejs-client: Cannot find module './docs'

Created on 18 Apr 2019  ยท  10Comments  ยท  Source: googleapis/google-api-nodejs-client

Environment details

  • OS: macOS
  • Node.js version: 10 and 11
  • npm version: n/a (yarn)
  • googleapis version: 39.2.0

Steps to reproduce

  1. yarn add --exact googleapis
  2. const { google } = require('googleapis')

Error: Cannot find module './docs' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15) at Function.Module._load (internal/modules/cjs/loader.js:508:25) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18) at Object.<anonymous> (/.../node_modules/googleapis/build/src/apis/index.js:77:14) at Module._compile (internal/modules/cjs/loader.js:701:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3)

needs more info p2 bug

Most helpful comment

This bug is relative to the .yarnclean file. This file is provided by Yarn to automatically remove useless files inside node_modules directory. By default, yarn autoclean --init generates a .yarnclean file that exclude docs directories:

# asset directories
docs
doc
website
images
assets

To reproduce the problem:

yarn init --yes
yarn install
yarn autoclean --init
yarn add googleapis 

node -e 'require("googleapis");'
# > Cannot find module './docs'

A very simple solution is to add an exception inside the .yarnclean file before installing googleapis package:

# asset directories
docs
!googleapis/build/src/apis/docs

But, without this change, yarn autoclean --init isn't compatible with googleapis...
The docs directory has been added in v37.2.0. So, this error only appears after v37.0.0.

All 10 comments

Seconded. Node version v10.15.0, googleapis version 39.2.0

const { google } = require('googleapis')
const people = google.people('v1')

The error is thrown on build. If you comment out the second line, where we get the people api, the build error goes away. Also tried installing googleapis version 38.0.0 and still got the error.

Looks like pinning "googleapis": "37.0.0" will solve this issue, as long as you don't depend on the changes from the last couple of versions.

@kilianc did 37.0.0 unblock you?

"googleapis": "37.0.0" works for me

I'm going to close this out for now. Please do let us know if you're still having problems!

I upgrade on version "googleapis": "^40.0.0" and i have still the same error ๐Ÿค”
I downgrade "googleapis": "37.0.0" to do my job

@aDEVE would you be able to provide a GitHub repository with a minimum reproduction of this bug?

Weird, I'm unable to reproduce this. Very specific steps for me, running OSX:

$ node -v
v11.15.0

$ yarn -v
1.16.0

$ yarn add --exact googleapis
yarn add v1.16.0
[1/4] ๐Ÿ”  Resolving packages...
[2/4] ๐Ÿšš  Fetching packages...
[3/4] ๐Ÿ”—  Linking dependencies...
[4/4] ๐Ÿ”จ  Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
โ””โ”€ [email protected]
info All dependencies
โ””โ”€ [email protected]
โœจ  Done in 0.47s.

$ cat server.js 
const {google} = require('googleapis');
const people = google.people('v1')
console.log(people);

$ yarn start
yarn run v1.16.0
$ node server.js
People {
  context:
   { _options: {},
...

Can you share:

  • What version of nodejs are you running?
  • What version of yarn?
  • Are you using electron?
  • Are you using webpack?
  • Are you using create-react-app?

This bug is relative to the .yarnclean file. This file is provided by Yarn to automatically remove useless files inside node_modules directory. By default, yarn autoclean --init generates a .yarnclean file that exclude docs directories:

# asset directories
docs
doc
website
images
assets

To reproduce the problem:

yarn init --yes
yarn install
yarn autoclean --init
yarn add googleapis 

node -e 'require("googleapis");'
# > Cannot find module './docs'

A very simple solution is to add an exception inside the .yarnclean file before installing googleapis package:

# asset directories
docs
!googleapis/build/src/apis/docs

But, without this change, yarn autoclean --init isn't compatible with googleapis...
The docs directory has been added in v37.2.0. So, this error only appears after v37.0.0.

Unless others have an idea of how to reasonably fix this on our side, I sadly think I need to close this out. The name docs and the accompanying directory is pretty key to the Google Docs product, and not something I think we can easily change. If others can think of something we could do - I would be more than happy to help!

I find it a little alarming that yarn would set a default like this that's potentially destructive. @bcoe you know anyone over on that side of the world?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joseparoli picture joseparoli  ยท  3Comments

rainabba picture rainabba  ยท  4Comments

Chethandsagar picture Chethandsagar  ยท  4Comments

streamnsight picture streamnsight  ยท  4Comments

madc0w picture madc0w  ยท  3Comments