Error deploying to Netlify: Cannot find module '../../../.redwood/datamodel.json'

Hi, I got to the deployment point of the blog tutorial and I am trying to deploy to Netlify with a mysql db hosted on Railway.

I already set the DATABASE_URL and the SESSION_SECRET on Netlify but when I go to deploy I get this error:

9:42:31 AM: ────────────────────────────────────────────────────────────────
9:42:31 AM:   Dependencies installation error                               
9:42:31 AM: ────────────────────────────────────────────────────────────────
9:42:31 AM: ​
9:42:31 AM:   Error message
9:42:31 AM:   A Netlify Function failed to require one of its dependencies.
9:42:31 AM:   Please make sure it is present in the site's top-level "package.json".
​
9:42:31 AM:   In file "/opt/build/repo/api/dist/functions/graphql.js"
9:42:31 AM:   Cannot find module '../../../.redwood/datamodel.json' from '/opt/build/repo/api/dist/models'
9:42:31 AM: ​
9:42:31 AM:   Resolved config
9:42:32 AM:   build:
9:42:32 AM:     command: yarn rw deploy netlify
9:42:32 AM:     commandOrigin: config
9:42:32 AM:     environment:
9:42:32 AM:       - DATABASE_URL
9:42:32 AM:       - SESSION_SECRET
9:42:32 AM:     publish: /opt/build/repo/web/dist
9:42:32 AM:     publishOrigin: config
9:42:32 AM:   functionsDirectory: /opt/build/repo/api/dist/functions
9:42:32 AM:   redirects:
9:42:43 AM:     - from: /*
      status: 200
      to: /index.html

I am using mariaDB locally and it’s working just fine. Any idea what it could be?

Your site is very nice, I wish I had your design chops.

I’ve only two entries [appended] at the top of my schema.prisma file, and I don’t have the word datamodel outside of node_modules…

Would you share your netlify.toml ?

And, Welcome, I say, Welcome! You’ve come to the right place!

Al;

ref: Netlify Deployment

btw: brand new video: David Price just posted an example of how he uses Redwood

Redwood Rules!
generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native"]
}

datasource DS {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

Hi,

I just realized that I had the connection limit missing on the db url env var. Although from the docs it appears to be recommended and not required. I am trying to redeploy with that change to see if that fixes it.

This is my netlify.toml, I haven’t changed it:

[build]
command = "yarn rw deploy netlify"
publish = "web/dist"
functions = "api/dist/functions"

[dev]
  # To use [Netlify Dev](https://www.netlify.com/products/dev/),
  # install netlify-cli from https://docs.netlify.com/cli/get-started/#installation
  # and then use netlify link https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
  # to connect your local project to a site already on Netlify
  # then run netlify dev and our app will be accessible on the port specified below
  framework = "redwoodjs"
  # Set targetPort to the [web] side port as defined in redwood.toml
  targetPort = 8910
  # Point your browser to this port to access your RedwoodJS app
  port = 8888

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

nope, still same issue

This is my current prisma schema

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

generator client {
  provider      = "prisma-client-js"
  binaryTargets = "native"
}

model User {
  id                  Int @id @default(autoincrement())
  name                String?
  email               String @unique
  hashedPassword      String
  salt                String
  resetToken          String?
  resetTokenExpiresAt DateTime?
}

model Post {
  id        String      @id @default(uuid())
  title     String
  body      String
  createdAt DateTime @default(now())
}

model Contact {
  id        String @id @default(uuid())
  name      String
  email     String
  message   String
  createdAt DateTime @default(now())
}

I checked on railway and it appears that the migration of the DB was ran propely, the tabels were created so the db url doesn’t seem to be the issue

One thing that I am using differently is that I am using the redwoodjs record lib, maybe that requires an extra step in the netlify build? or there is an error there?

I was able to get a bit further by changing the deploy command in the netlify. toml file but still getting this weird issue at the end

I changed from:

command = "yarn rw deploy netlify"

to:

command = "yarn rw record init && yarn rw deploy netlify"

And not I get to the end of the deploy and it says that some how it was canceled but I didn’t cancel it.

cc: @rob since it relates to RedwoodRecord

11:31:37 AM: ────────────────────────────────────────────────────────────────
11:31:37 AM:   2. Functions bundling                                         
11:31:37 AM: ────────────────────────────────────────────────────────────────
11:31:37 AM: ​
11:31:37 AM: Packaging Functions from api/dist/functions directory:
11:31:37 AM:  - auth.js
11:31:37 AM:  - graphql.js
11:31:37 AM: ​
11:32:05 AM: ​
11:32:05 AM: (Functions bundling completed in 28.2s)
11:32:05 AM: ​
11:32:05 AM: ────────────────────────────────────────────────────────────────
11:32:05 AM:   3. Deploy site                                                
11:32:05 AM: ────────────────────────────────────────────────────────────────
11:32:05 AM: ​
11:32:05 AM: Starting to deploy site from 'web/dist'
11:32:10 AM: Creating deploy tree 
11:32:10 AM: Creating deploy upload records
11:32:10 AM: 1 new files to upload
11:32:10 AM: 1 new functions to upload
11:32:16 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
11:32:19 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
11:32:22 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
11:32:24 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
11:32:27 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
11:32:30 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
11:32:36 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
11:32:43 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
11:32:54 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
11:33:10 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
11:33:37 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
11:33:53 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
11:33:53 AM: Failed to upload file: graphql
11:33:53 AM: Site deploy was successfully initiated
11:33:53 AM: ​
11:33:53 AM: (Deploy site completed in 1m 47.8s)
11:33:53 AM: ​
11:33:53 AM: ────────────────────────────────────────────────────────────────
11:33:53 AM:   Netlify Build Complete                                        
11:33:53 AM: ────────────────────────────────────────────────────────────────
11:33:53 AM: ​
11:33:53 AM: (Netlify Build completed in 3m 34.1s)
11:33:53 AM: Execution cancelled
11:33:53 AM: Error running command: Command was cancelled
11:33:53 AM: Failing build: Failed to build site
11:33:53 AM: Finished processing build request in 5m40.584157527s

Hmmmmmmm that error looks like the resulting function is too big for Netlify to be able to deploy to a Lambda: Request must be smaller than 69905067 bytes for the CreateFunction operation - Support - Netlify Support Forums So it’s Netlify cancelling the build. The more dependencies you have the bigger that function is going to get, but RR doesn’t have any wildly different deps than anything else (mostly just Prisma).

Unless RR itself is causing something to balloon in size…can you try running yarn rw build locally and see if that completes? I don’t think that prepares the built files in the same way that Netlify does, they have an extra step called zip-it-and-ship-it that prepares the files for AWS Lambda: https://github.com/netlify/zip-it-and-ship-it There may be a way to run that locally in Redwood…I’m waiting to hear back from some Redwood folks if that’s the case.

Hi, I tried that and it compiled quickly.

I made the repo I am working with public for the time being in case it helps having access to the files to see what’s going on.

Here is the link to the repo: https://github.com/aguscha333/agch

I confirmed that our build process with yarn rw build doesn’t use the zip-it-and-ship-it in any way. But, we could install and run it manually: https://github.com/netlify/zip-it-and-ship-it

It sounds like srcFolders just needs to be the api/src/functions folder, after going through yarn rw build. But that process might just blow up with the same error. :frowning:

We’ve actually got a doc on how to do it locally! Docs - Builds : RedwoodJS Docs

I ran those steps and it finished with no errors in 18s. Not sure what else to try

Can you find the zipped up files somewhere? And if so, how big are they? I’m thinking we could unzip and poke through them and see if there’s some weird circular dependency that’s taking up way too much disk space.

I checked, not sure if it is normal but inside the zipped balls as they call them, the node modules folder is really big and when looking into that, they all appear to be normal except for prisma that is 220mb

The bulk of it comes from the sdk and the engines folder:

Hmm I’ve got the SDK in there as a dependency of RR, but maybe it can be a devDependency: I’m pretty sure it’s only used on yarn rw record init. But then the datamodel.json file would have to get moved somewhere that can be checked in so that it’s available at deploy time and won’t need to be created by Netlify. Maybe it could go in api/src/models along with everything else? Or in api/src/db along with the other database stuff, but I don’t know if Prisma will freak out if there’s a file in there that it doesn’t manage itself.

So maybe just a change to:

and

And that’ll bring the bundle size back under control?

I can try that out see if it reduces the zipballs size locally. I like it going in api/src/models. I’ll keep you posted and if it works I’ll create a PR.

1 Like

Hi again. I’ve made some progress with this but I am a bit stuck at the moment.

So far I’ve:

  • moved the sdk to be a dev dependency
  • moved the location of the datamodel.json to the models folder as we said
  • Fixed the parseDatamodel method to ignore the file as it does with index.js for getting the model names
  • fixed prebuildApiFiles and findApiFiles to copy this json file to the pre-build

The next step would be to make sure that the json file is being correctly placed in the dist folder when running the build or dev commands.

Right now the issue I am seeing is that something is taking that .json file and transforming it into a js file with a source map associated file.

I am not very familiar wirth the build files so it is a bit hard for me to debug.

I can post what I have so far as a draft PR and we can collaborate there. WDYT?

1 Like

I’m betting it’s a Webpack and/or Babel config somewhere that’s doing this…and I’m no expert in those.

That would be great if you could open a PR and then I can pull in a couple of folks that are more familiar with Webpack/Babel to help!

Thanks for the work on this!

PR created :smile: