Prisma1: fs.pathExistsSync is not a function

Created on 17 Oct 2017  路  10Comments  路  Source: prisma/prisma1

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

bu2-confirmed arecli

Most helpful comment

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... :tada:

...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_

All 10 comments

Are you deploying locally or to a shared cluster?

I'm deploying to my project on graph.cool

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?

Yes, you are supposed to get 0.7.0.

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.

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

The issue goes away if I install [email protected]

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... :tada:

...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_

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

This is fixed and published at [email protected]

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marktani picture marktani  路  3Comments

schickling picture schickling  路  3Comments

marktani picture marktani  路  3Comments

AlessandroAnnini picture AlessandroAnnini  路  3Comments

dohomi picture dohomi  路  3Comments