Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Provided module can't be loaded" error when trying to load GoogleCloud Datastore module with Nodejs 8

As part of the implementation of a Cloud Function under Google Cloud Platform, executed with Nodejs 8, I have to store information in GCP Datastore.

I use TypeScript which is compiled in Javascript.

I have the following error when I try to import the "@google-cloud/datastore" module:

Provided module can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: TypeError: extend must be a string

I tried 2 ways to import the module and each time I get the same error:

import {Datastore} from '@google-cloud/datastore';
const datastore = new Datastore();

or

const datastore = require('@google-cloud/datastore');

I also tried to install different versions of the module, nothing helps.

Finally, I realized that even when the module is not installed (I executed the command npm uninstall @google-cloud/datastore), I get the exact same error when logically, when we try to import a module which is not installed, we should have the following error:

Provided module can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'test'

Has anyone ever encountered this problem or would have a clue why I get this error?

like image 913
Lionel Loubrie Avatar asked Jul 21 '26 13:07

Lionel Loubrie


1 Answers

I faced the same issue while deploying the functions, later I realized that I installed the packages in wrong location.

My folder structure was this:

  • /
    • functions
      • node_modules
      • index.js ...

By mistake I installed all the packages at / level:

  • /
    • functions
      • node_modules
      • index.js ...
    • node_modules

So all my packages were in the outer node_modules.

like image 66
Satyam Rai Avatar answered Jul 23 '26 01:07

Satyam Rai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!