Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

fs.pathExistsSync is not a function #875

Closed
lastmjs opened this issue Oct 17, 2017 · 10 comments
Closed

fs.pathExistsSync is not a function #875

lastmjs opened this issue Oct 17, 2017 · 10 comments

Comments

@lastmjs
Copy link

lastmjs commented Oct 17, 2017

When I run graphcool deploy I get the following error in the terminal:

fs.pathExistsSync is not a function

My graphcool.yml has the following format for functions:

functions:
    assignment-lti-launch:
        handler:
            code:
                src: ./functions/assignment-lti-launch/assignment-lti-launch.ts
                environment:
                    PRENDUS_LTI_SECRET: ${env:PRENDUS_LTI_SECRET}
        type: resolver
        schema: ./functions/assignment-lti-launch/assignment-lti-launch.graphql

When I deploy with the functions defined as above, I get the error. When I remove the functions section, everything deploys fine

@marktani
Copy link
Contributor

Are you deploying locally or to a shared cluster?

@lastmjs
Copy link
Author

lastmjs commented Oct 17, 2017

I'm deploying to my project on graph.cool

@lastmjs
Copy link
Author

lastmjs commented Oct 17, 2017

Hold on, maybe I'm confused. If I do an npm install graphcool@next right now, am I supposed to get version 0.7.0?

@marktani
Copy link
Contributor

marktani commented Oct 17, 2017

Yes, you are supposed to get 0.7.0.

@lastmjs
Copy link
Author

lastmjs commented Oct 17, 2017

Alright, it looks like my graphcool.yml follows the schema, and I'm on version 0.7.0, and yes this error continues to appear.

@lastmjs
Copy link
Author

lastmjs commented Oct 17, 2017

Also, the error continues to appear even if the function is a .js file instead of a .ts file.

@lastmjs
Copy link
Author

lastmjs commented Oct 17, 2017

The issue goes away if I install graphcool@0.7.0-beta.12

@kbrandwijk
Copy link
Contributor

kbrandwijk commented Oct 17, 2017

Okay, very complicated scenario, but @lastmjs and me figured it out. First of all, the fs-extra dependency is missing from the graphcool-cli-core package. This is the main cause of this problem.

Now what happens? Once graphcool-cli-core requires fs-extra, it starts looking for it. It will not find it in its own node_modules folder, and will look one folder up, where fs-extra was installed, because it is required by graphcool-cli and graphcool-cli-engine. So everything works... 🎉

...Except, if you happen to have another project dependency that uses a different version of fs-extra, which was the case. Then, that version is already installed in node_modules, and when you install graphcool, npm does some conflict resolution and places the conflicting dependency for graphcool in it's node_modules folder. So it ends up in graphcool-cli/node_modules and graphcool-cli-engine/node_modules, but NOT in graphcool-cli-core/node_modules, because that package doesn't have the dependency specified. At runtime, the resolved version for all require statements in graphcool-cli-core will be the one from the top node_modules folder.

Normal install:

./node_modules/graphcool-cli
./node_modules/graphcool-cli-core
./node_modules/graphcool-cli-engine
./node_modules/fs-extra
./node_modules/.....

Install with existing conflicting version:

./node_modules/graphcool-cli/node_modules/fs-extra  <-- correct version
./node_modules/graphcool-cli-core <-- this module will look for fs-extra at the top level, causing the error!
./node_modules/graphcool-cli-engine/node_modules/fs-extra <-- correct version
./node_modules/fs-extra <-- old, existing version
./node_modules/.....

This happened to be fs-extra 0.30.0, which does not include fs.pathExistsSync().

So the bottom line is: Please check the package.json dependencies for all CLI components

@timsuchanek
Copy link
Contributor

Thanks for researching this already so well @kbrandwijk @lastmjs @marktani ! I will add fs-extra to the cli core and check the others dependencies.

@timsuchanek
Copy link
Contributor

This is fixed and published at graphcool@0.8.0-alpha.8

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants