google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

Uncaught TypeError: fs.readdirSync is not a function

Open khalidadil opened this issue 10 years ago • 2 comments

I'm building a Meteor 1.3 app and I'm getting this error when I add import the googleapis node package into my client side React component:

Uncaught TypeError: fs.readdirSync is not a function

It looks like it's coming from this code block in the package:

fs.readdirSync(path.join(__dirname, '../apis')).forEach(function (file) {
  apis[file] = requireAPI('../apis/' + file);
});

I'm importing the package using: import google from 'googleapis';

Is this because fs is a server side package and doesn't work on the client?

Can I use this package on the client side in the browser?

Thanks!

khalidadil avatar May 10 '16 19:05 khalidadil

This library (google-api-nodejs-client) will not work in the browser, only in Node.js.

jmdobry avatar May 10 '16 19:05 jmdobry

Hey guys I'm getting the same error but on server. For example if I want to export a function then it would throw 'Uncaught TypeError: fs.readdirSync is not a function'. This is caused by 'import google from 'googleapis';'

for example

test1.js >

import google from 'googleapis'; export function hello(){}

test2.js

import {hello} from './test1.js'

this will throw the error. Function is being exported and imported (used) on the server.

d4lek avatar Oct 11 '16 11:10 d4lek