Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prisma generate script throws error #2049

Closed
yantakus opened this issue Mar 31, 2020 · 25 comments
Closed

Prisma generate script throws error #2049

yantakus opened this issue Mar 31, 2020 · 25 comments
Assignees
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug.
Milestone

Comments

@yantakus
Copy link

When I'm trying to run this example: https://github.com/prisma/prisma-examples/tree/master/typescript/graphql-auth

I'm getting the following problem. When running npm i I get this error:

> @prisma/client@2.0.0-preview025 postinstall /Users/yan/Projects/prisma-examples/typescript/graphql-auth/node_modules/@prisma/client
> node scripts/postinstall.js

Error: ENOENT: no such file or directory, mkdir

... Skip lines. Everything is ok here ...

> prisma2 generate

Error: ENOENT: no such file or directory, mkdir
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! graphql-auth@ generate:prisma: `prisma2 generate`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the graphql-auth@ generate:prisma script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/yan/.npm/_logs/2020-03-31T06_04_32_492Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! graphql-auth@ generate: `npm run generate:prisma && npm run generate:nexus`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the graphql-auth@ generate script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/yan/.npm/_logs/2020-03-31T06_04_32_519Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! graphql-auth@ postinstall: `npm run generate`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the graphql-auth@ postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/yan/.npm/_logs/2020-03-31T06_04_32_556Z-debug.log

and here is the above mentioned log file contents:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/usr/local/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'run',
1 verbose cli   'generate:prisma'
1 verbose cli ]
2 info using npm@6.14.4
3 info using node@v13.7.0
4 verbose run-script [ 'pregenerate:prisma', 'generate:prisma', 'postgenerate:prisma' ]
5 info lifecycle graphql-auth@~pregenerate:prisma: graphql-auth@
6 info lifecycle graphql-auth@~generate:prisma: graphql-auth@
7 verbose lifecycle graphql-auth@~generate:prisma: unsafe-perm in lifecycle true
8 verbose lifecycle graphql-auth@~generate:prisma: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/yan/Projects/prisma-examples/typescript/graphql-auth/node_modules/.bin:/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/yan/Projects/prisma-examples/typescript/graphql-auth/node_modules/.bin:/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/yan/Projects/prisma-examples/typescript/graphql-auth/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
9 verbose lifecycle graphql-auth@~generate:prisma: CWD: /Users/yan/Projects/prisma-examples/typescript/graphql-auth
10 silly lifecycle graphql-auth@~generate:prisma: Args: [ '-c', 'prisma2 generate' ]
11 silly lifecycle graphql-auth@~generate:prisma: Returned: code: 1  signal: null
12 info lifecycle graphql-auth@~generate:prisma: Failed to exec generate:prisma script
13 verbose stack Error: graphql-auth@ generate:prisma: `prisma2 generate`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:321:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:321:20)
13 verbose stack     at maybeClose (internal/child_process.js:1026:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid graphql-auth@
15 verbose cwd /Users/yan/Projects/prisma-examples/typescript/graphql-auth
16 verbose Darwin 19.0.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "generate:prisma"
18 verbose node v13.7.0
19 verbose npm  v6.14.4
20 error code ELIFECYCLE
21 error errno 1
22 error graphql-auth@ generate:prisma: `prisma2 generate`
22 error Exit status 1
23 error Failed at the graphql-auth@ generate:prisma script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

I tried to remove node_modules and install again with no luck.

Any ideas?

@yantakus
Copy link
Author

It works fine on my other (windows) computer, so this is definitely something wrong with my working mac. Any help appreciated!

@janpio
Copy link
Member

janpio commented Mar 31, 2020

We recently updated the examples to use beta.1. Can you maybe try again if this exists with that version of Prisma?

@yantakus
Copy link
Author

@janpio no luck with the latest version as well. Here is the full log after running npm i in prisma-examples/typescript/graphql-auth directory: https://gist.github.com/yantakus/5466d99495d6a719435aca23d7f9c8e4

@yantakus
Copy link
Author

yantakus commented Apr 1, 2020

I upgraded node to the latest version (node v13.12.0, npm 6.14.4) and it gave me a better error output:

Error: EACCES: permission denied, mkdir '/Users/yan/.cache/prisma'

So after creating this directory manually it worked fine!

@yantakus yantakus closed this as completed Apr 1, 2020
@janpio
Copy link
Member

janpio commented Apr 1, 2020

This is actually a problem we need to look into - I will move the issue to the correct place then. Thanks for giving us an update!

(Internal note: .cache/prisma is the path for the binary download I think, so this not being creatable we should probably catch somehow)

@janpio janpio reopened this Apr 1, 2020
@janpio janpio transferred this issue from prisma/prisma-examples Apr 1, 2020
@timsuchanek timsuchanek self-assigned this Apr 2, 2020
@timsuchanek timsuchanek added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. labels Apr 2, 2020
@timsuchanek
Copy link
Contributor

Thanks for reporting. We now catch, if the cache behavior fails, as it's optional and not needed for the generate command to succeed.

@janpio janpio added this to the Beta 2 milestone Apr 2, 2020
@RussMax783
Copy link

@timsuchanek I'm running into this same issue on the the 2.0.0-beta.2 version, but not locally. I went to deploy the upgrade on AWS Elastic Beanstalk and started getting this error. The version I had previously deployed was preview021 and it worked just fine. I've been trying to track down if there are permissions issues or something but am having no luck. I totally get that there are a million use cases and build environments to consider so I'm not expecting anyone to know and fix my problem. Just wanted to update that there are probably a lot of other use cases where this will cause problems.

image

Whats interesting to me is that i see those logs, and then the failure. I'm not sure how to provide more information on this bad boy. But I'm happy to answer questions and help dig into it.

@janpio
Copy link
Member

janpio commented Apr 10, 2020

You can try setting DEBUG=* as an env var to get more output hopefully.

@RussMax783
Copy link

nodejs.log

Here is the log from elastic beanstalk after setting DEBUG=* Starts at the bottom of the file.

@pantharshit00 pantharshit00 reopened this Apr 13, 2020
timsuchanek added a commit that referenced this issue Apr 14, 2020
Former-commit-id: 1a8d788
Former-commit-id: 9c6ee3f
@timsuchanek timsuchanek reopened this Apr 15, 2020
@timsuchanek
Copy link
Contributor

Thanks for reporting @RussMax783!

It looks like you're trying to run prisma generate, while maybe the filesystem can't be accessed within your AWS Elastic Beanstalk.

If that is the case, we should for sure catch the error nicer.

The action item from our side: Improve the error message.
If you e.g. do a simple fs.writeFileSync('test', 'test') in your application, you can validate, if you can write to the filesystem or not.

@RussMax783
Copy link

I created a node script and ran it right before running prisma generate. The script looks like this:

const fs = require('fs')

console.log('RUNNING TEST')

console.log('Current path: ', __dirname)

fs.writeFileSync('test', 'test')

fs.readdir('./', function(err, items) {
  console.log(items)

  for (var i = 0; i < items.length; i++) {
    console.log(items[i])
  }
})

console.log('FINISHED RUNNING TEST')

and the log looks like this.

RUNNING TEST
Current path:  /var/app/current/src
FINISHED RUNNING TEST
[
  'dist',
  'node_modules',
  'npm-shrinkwrap.json',
  'package.json',
  'prisma',
  'src',
  'test'
]
dist
node_modules
npm-shrinkwrap.json
package.json
prisma
src
test

@RussMax783
Copy link

@timsuchanek Because I still see the message that the generate command succeeded (the you can now start using prisma client...) I had the idea to wrap calling prisma generate in a script and allow the environment to keep moving on and start. It seems to have worked! My Elastic beanstalk is now up and running and seems to be working just fine. So I wonder if there is some async command being run to create some directory and its being thrown after the fact. Happy to dig in more.

@matthewmueller
Copy link
Contributor

matthewmueller commented Aug 24, 2020

@RussMax783 are you still seeing this after you generate inside Elastic Beanstalk?

Does it still log

Error: Error: ENOENT: no such file or directory, mkdir
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! maxway-server@0.0.1 prestart: `DEBUG=* prisma generate`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the maxway-server@0.0.1 prestart script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

When you do not have DEBUG=*?

@kimchhickey
Copy link

I am trying to run prisma generate in AWS Elastic Beanstalk. I got the error, either. How is it going?

@pantharshit00
Copy link
Contributor

@kimchhickey Can you please lay out the reproductions steps that I can use to reproduce this in elastic beanstalk. That will help a lot!

Also, please paste the actual error message that you are getting here

@johhansantana
Copy link

I just recently have this issue:

[Error: EACCES: permission denied, mkdir '/var/app/staging/node_modules/.prisma'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/var/app/staging/node_modules/.prisma'
}
Error: Can't write to /var/app/staging/node_modules/@prisma/cli please make sure you install "@prisma/cli" with the right permissions.
Error: Can't write to /var/app/staging/node_modules/@prisma/sdk please make sure you install "@prisma/cli" with the right permissions.

I am basically creating a simple instance in AWS EBS UI
Then I .zip all my prisma files and upload that.
Then it gives me the above error.

@johhansantana
Copy link

I was able to fix this by adding a file in the root folder called .npmrc then adding inside this unsafe-perm=true

@janpio
Copy link
Member

janpio commented Sep 25, 2020

Can you please open a new issue with just the text you posted here @johhansantana please? We should and want to look into this, but that is much easier with a separate issue just for your case. Thanks.

@croossin
Copy link

@johhansantana Thanks for the tip... I got past the invalid access issue.. but then ran into the following issue. Did you see this too?

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
info The postinstall script automatically ran `prisma generate`, which failed.
The postinstall script still succeeds but won't generate the Prisma Client.

@janpio
Copy link
Member

janpio commented Mar 23, 2021

That is just an information and should not block anything @croossin.

I am going to close this now. Happy to take a look again if we get more information.

@janpio janpio closed this as completed Mar 23, 2021
@lc443
Copy link

lc443 commented Feb 1, 2022

on my Mac I did sudo prism generate then it worked

@aarjan
Copy link

aarjan commented Mar 24, 2022

I had this issue in my docker container.
Mine was fixed by changing the ownership of the node_modules/.prisma folder from root to the default one.

@KinjalWS
Copy link

I had this issue in my docker container. Mine was fixed by changing the ownership of the node_modules/.prisma folder from root to the default one.

Can you please elaborate on this @aarjan ?

@aarjan
Copy link

aarjan commented May 23, 2022

I had this issue in my docker container. Mine was fixed by changing the ownership of the node_modules/.prisma folder from root to the default one.

Can you please elaborate on this @aarjan ?

I changed it from root to node
chown -R node_modules/.prisma node:node

@sostenesapollo
Copy link

bash-3.2$ chown -R node_modules/.prisma node:node
chown: node_modules/.prisma: illegal user name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug.
Projects
None yet
Development

No branches or pull requests