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

1

6

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?

Erfert answered 13/1, 2020 at 11:6 Comment(3)
see this github.com/googleapis/nodejs-datastore#using-the-client-library maybe it will helpCarce
did you added the module into the dependencies in your package.json? if not add it "@google-cloud/datastore": "^5.0.3"Goutweed
I did add the module in the dependencies in my package.json. I also did look at the documentation but found nothing helpful. There appears to be a conflict between Datastore and QuickBase. In my index file, I have other GCP functions that use QuickBase. When I comment all calls to QuickBase, my function using Datastore compiles without error. Has anyone ever encountered this conflict and might know how to resolve this ?Erfert
H
12

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.

Halothane answered 10/10, 2020 at 10:22 Comment(4)
I am facing the same issue, How can I change the wrong package location?Sattler
@MarkChoi Change your directory; cd ./functions/ and then run the npm install <module> command.Wait
I did the same thing, and the solution helped me to solve this problem. But what files can be deleted due to they are in the wrong place?Niehaus
@HogRider you can delete the entire node_modules folder present in the wrong location this is only if you have done npm install in the wrong location.Halothane

© 2022 - 2024 — McMap. All rights reserved.