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

Deployment on AWS: TypeError: Cannot read property '$create' of undefined #385

Closed
jatidevelopments opened this issue Nov 17, 2021 · 9 comments

Comments

@jatidevelopments
Copy link

jatidevelopments commented Nov 17, 2021

What is the problem?

I have successfully deployed BlitzJS to AWS. However, when I try to login or signup an account I get an Error:
Blitz.JS Deployment: TypeError: Cannot read property '$create' of undefined

I think this issue is related to #13

I don't wrap the config like in the issue in 2955, so I don't get why it's not working correctly. BlitzJS is supported with this module, right?

Maybe it has something to do with the next-tf package. I found in "terraform-aws-next-js/packages/tf-next/src/utils/index.ts" that its parsing for next.config.js not blitz.config.js. Maybe because of that blitz can not wrap around next?

Has anybody an idea how I could fix it? Would really appreciate if somebody know a solution!

Paste all your error logs here:

Bildschirmfoto 2021-11-17 um 14 46 15

Paste all relevant code snippets here:

PASTE_HERE (leave the ``` marks)

What are detailed steps to reproduce this?

  1. yarn tf-next
  2. terraform apply

Run blitz -v and paste the output here:

Linux 4.14 | linux-x64 | Node: v16.13.0

blitz: 0.42.4 (local)

  Package manager: yarn 
  System:
    OS: Linux 4.14 Amazon Linux 2
    CPU: (1) x64 Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
    Memory: 730.95 MB / 1.94 GB
    Shell: 4.2.46 - /bin/bash
  Binaries:
    Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
    Yarn: 1.22.17 - /usr/bin/yarn
    npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: 2.x => 2.30.3 
    blitz: 0.42.4 => 0.42.4 
    prisma: 2.x => 2.30.3 
    react: alpha => 18.0.0-alpha-cb11155c8-20211112 
    react-dom: alpha => 18.0.0-alpha-cb11155c8-20211112 
    typescript: 4.4.4 => 4.4.4 

Please include below any other applicable logs and screenshots that show your problem:

  • Yes, I specifically disabled the wrapping with next-pwa and it doesn't work. Even run terrafrom destroy, deleted .tf-next then build again with yarn tf-next and deployed again with terraform apply.
  • I am building on EC2 instance via Cloud9 on Amazon Linux
@jatidevelopments
Copy link
Author

Related to: milliHQ/terraform-aws-next-js#239

@flybayer
Copy link
Member

Hey @jatidevelopments, I'm not sure if we've had anyone use this module with Blitz yet.

In order for Blitz auth to work correctly, we need the .blitz.config.compiled.js file to be available at runtime. This is generated in the project root at build time. The reason it's compiled is because we support blitz.config.ts

Probably the terraform module needs updated to read that file if it detects Blitz.

@ofhouse
Copy link

ofhouse commented Nov 17, 2021

Would agree that this is not an issue with Blitz but with the Terraform module.
We currently build with the legacy experimental-serverless-trace target and due to that we always create a wrapper next.config.js that then requires the original config when running tf-next build.

We are in the process of removing the wrapper, so this should be resolved soon.

@flybayer
Copy link
Member

Ok, then a workaround that probably would work is use patch-package to change next.config.js in the terraform module to .blitz.config.compiled.js.

@jatidevelopments
Copy link
Author

jatidevelopments commented Nov 18, 2021

Ok, then a workaround that probably would work is use patch-package to change next.config.js in the terraform module to .blitz.config.compiled.js.

Hi @flybayer thanks for the support!

I patched the tf-next package with patch-package to .blitz.config.compiled.js. Didn't helped.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findEntryPoint = void 0;
const path_1 = require("path");
const fs_1 = require("fs");
// Looks for a `package.json` or `next.config.js` file in cwd and
// returns the result as a relative path to the basePath
function findEntryPoint(cwd) {
    
    console.log("CHANGED THE PACKAGE")
    
    for (const entrypoint of ['package.json', '.blitz.config.compiled.js']) {
        if ((0, fs_1.existsSync)((0, path_1.join)(cwd, entrypoint))) {
            return entrypoint;
        }
    }
    throw new Error(`No package.json or next.config.js could be found in ${cwd}`);
}
exports.findEntryPoint = findEntryPoint;

I think I need to change next.config.js in the terraform module. How am I able to do so? patch-packageis only for npm packages not for terrafrom.

@jatidevelopments
Copy link
Author

Hi @ofhouse, could you tell me how long it will take to publish the new version? I need to get it work by next week.

@ofhouse
Copy link

ofhouse commented Nov 18, 2021

I think I need to change next.config.js in the terraform module. How am I able to do so? patch-packageis only for npm packages not for terrafrom.

Quick explainer here: The "module" consists of two parts:

  1. The CLI tf-next
  2. The deployable Terraform code

The CLI creates a package from your Blitz / Next.js source that is consumable by AWS Lambda.
Terraform then picks up the package and creates AWS resources from it that are then deployed.

So Terraform only deploys static files generated by the CLI, but does not modify or build any of the Blitz or Next source code.
So the CLI ist responsible for producing an invalid package for Blitz here.


Not a big fan of giving ETAs on my Open Source projects since my estimates for update plans were mostly mixed up by my (paid) work in the past 😅
I'll try to take a look at it over the weekend.

@jatidevelopments
Copy link
Author

I think I need to change next.config.js in the terraform module. How am I able to do so? patch-packageis only for npm packages not for terrafrom.

Quick explainer here: The "module" consists of two parts:

  1. The CLI tf-next
  2. The deployable Terraform code

The CLI creates a package from your Blitz / Next.js source that is consumable by AWS Lambda. Terraform then picks up the package and creates AWS resources from it that are then deployed.

So Terraform only deploys static files generated by the CLI, but does not modify or build any of the Blitz or Next source code. So the CLI ist responsible for producing an invalid package for Blitz here.

Not a big fan of giving ETAs on my Open Source projects since my estimates for update plans were mostly mixed up by my (paid) work in the past 😅 I'll try to take a look at it over the weekend.

Hmm... Yeah I already thought that the CLI is responsible for building the Lambda Functions. That's why I was confused why changing the next.config.js to the builded blitz.js config as @flybayer commented didn't helped.

Would be great if you could fix it over the weekend. I would maybe give a bug bounty reward if this helps for your motivation ;)

Other than that if you know a workaround for short. Then I would appreciate that too!

@ofhouse
Copy link

ofhouse commented Nov 21, 2021

Learned today that Vercel is still forcing experimental-serverless-trace as build target when it detects Blitz.
So using the server target as suggested and implemented by milliHQ/terraform-aws-next-js#89 would not help in this case.
I would follow Vercel's evaluation that server target and serverless environment is currently not working for Blitz.

Have you tried to deploy it on Vercel if the error is also present there?

@dillondotzip dillondotzip transferred this issue from blitz-js/blitz Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants