H4ad / serverless-adapter-examples

Working examples to show how to integrate with https://github.com/H4ad/serverless-adapter
https://viniciusl.com.br/serverless-adapter
MIT License
12 stars 0 forks source link

Unable to run on digitalocean function #2

Closed jmd9019 closed 2 years ago

jmd9019 commented 2 years ago

Hi @H4ad , I was trying https://github.com/H4ad/serverless-adapter-examples/tree/master/examples/trpc-digital-ocean to deploy to digital ocean functions I added npm package instead of file link in package.json "@h4ad/node-modules-packer": "^1.1.0", I was able to deploy correctly but when I click run on DO functions I am getting error

2022-09-11T13:27:48.168357007Z stdout: Error: Cannot find module '@h4ad/serverless-adapter'
2022-09-11T13:27:48.168412462Z stdout: Require stack:
2022-09-11T13:27:48.168415989Z stdout: - /tmp/ZWzb5Bqh/dist/index.js
2022-09-11T13:27:48.168418343Z stdout:     at Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
2022-09-11T13:27:48.168422641Z stdout:     at Module._load (node:internal/modules/cjs/loader:804:27)
2022-09-11T13:27:48.168425056Z stdout:     at Module.require (node:internal/modules/cjs/loader:1022:19)
2022-09-11T13:27:48.16842743Z  stdout:     at require (node:internal/modules/cjs/helpers:102:18)
2022-09-11T13:27:48.168429805Z stdout:     at Object.<anonymous> (/tmp/ZWzb5Bqh/dist/index.js:4:30)
2022-09-11T13:27:48.168433032Z stdout:     at Module._compile (node:internal/modules/cjs/loader:1120:14)
2022-09-11T13:27:48.168435366Z stdout:     at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
2022-09-11T13:27:48.16843776Z  stdout:     at Module.load (node:internal/modules/cjs/loader:998:32)
2022-09-11T13:27:48.168440095Z stdout:     at Module._load (node:internal/modules/cjs/loader:839:12)
2022-09-11T13:27:48.168442389Z stdout:     at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29) {
2022-09-11T13:27:48.168444864Z stdout:   code: 'MODULE_NOT_FOUND',
2022-09-11T13:27:48.168447138Z stdout:   requireStack: [ '/tmp/ZWzb5Bqh/dist/index.js' ]
2022-09-11T13:27:48.168449402Z stdout: }
2022-09-11T13:27:48.171598Z    stderr: The action did not initialize or run as expecte
H4ad commented 2 years ago

Hey @jmd9019, thanks for using serverless-adapter.

Some questions:

jmd9019 commented 2 years ago

Yes I am using NPM and i am using VS Code as IDE and my PC is windows. Also I am trying to deploy on DO functions

jmd9019 commented 2 years ago

And to be clear, as of now I am just deploying to DO's function and try to send get GET request to URL provided by DO's function

H4ad commented 2 years ago

Maybe the problem is with Windows, @h4ad/node-modules-packer may not be able to bundle the @h4ad/serverless-adapter library.

To test, zip the dist folder and the node_modules folder into a file called deploy.zip, then move this zip folder to packages/api/prod and replace the zip that was there.

Then run npm run update-function to update your code inside the DO.

H4ad commented 2 years ago

Also, inside package.json, did you change the @h4ad/serverless-adapter for @h4ad/node-modules-packer or is just a typo issue in your description here "I added npm package instead of file link in package.json "@h4ad/node-modules-packer": "^1.1.0",". If you changed, this could be the issue too, inside package.json, in production dependencies, you must have @h4ad/serverless-adapter version 2.10.0 at least.

jmd9019 commented 2 years ago

I think its correctly creating deploy.zip I looked into zip file It had 2 file node_modules and dist which has the code

jmd9019 commented 2 years ago

Here's the dependencies inside package.json

  "dependencies": {
    "@h4ad/node-modules-packer": "^1.1.0",
    "@h4ad/serverless-adapter": "^2.10.0",
    "@trpc/server": "9.27.0",
    "zod": "^3.18.0"
  },
H4ad commented 2 years ago

I think its correctly creating deploy.zip I looked into zip file It had 2 file node_modules and dist which has the code

Look inside node_modules, there is a @h4ad folder and inside it is serverless-adapter.

jmd9019 commented 2 years ago

Ok inside deploy.zip in node_modules there is no folder @h4ad but in my PC's node_modules there is @h4ad folder

jmd9019 commented 2 years ago

I will try this https://github.com/H4ad/serverless-adapter-examples/issues/2#issuecomment-1242976900 and see if I can make some progress

jmd9019 commented 2 years ago

Hi @H4ad , I did it manually now creating deploy.zip and used npm run update-function. Still there is error I am sending GET request to '/getUser'

export const appRouter = trpc
  .router<TrpcContext>()
  .transformer(new BufferToJSObjectTransformer())
  .query('getUser', {
    async resolve() {
      return { name: 'Bilbo' };
    },
  })

Getting error as "2022-09-11T15:16:26.332147Z stderr: The action did not initialize or run as expected. Log data might be missing."

H4ad commented 2 years ago

When you call the API inside DO, you should add the prefix of your folders inside package, so instead /getUser, you call /api/prod/getUser.

jmd9019 commented 2 years ago

This the url : https://faas-blr1-8177d592.doserverless.co/api/v1/web/fn-c2f6a867-3589-4d9d-be04-a587c0224939/api/prod/getUser

H4ad commented 2 years ago

Let's just summarize:

About the code, did you change anything? Because these errors sound like something related to the tRPC code. What about project.yml, did you change anything in the example?

Are you receiving any logs inside DO?

jmd9019 commented 2 years ago

Yes did follow all 3 points About code nothing is changed also nothing is changed on project.yml

packages:
  - name: api
    functions:
      - name: 'prod'
        main: 'dist/index.main'
        runtime: 'nodejs:18'
        web: 'raw'

DO logs under logs tab

"logs":[
0:"2022-09-11T15:56:52.996200Z    stderr: The action did not initialize or run as expected. Log data might be missing."
]
"response":{
  "result": {
    "error": "The action exceeded its time limits of 10000 milliseconds during initialization."
  },
  "size": null,
  "status": "action developer error",
  "success": false
}
H4ad commented 2 years ago

Strange, very strange, everything seems fine.

Try using this zip folder to deploy, I created it using linux and running @h4ad/node-modules-packer: deploy.zip

If it works, try to see if there are any differences between the files inside dist or see if any dependencies are missing inside node_modules.

jmd9019 commented 2 years ago

Yes, your deploy.zip is working but I don't see any packages missing in my deploy (2).zip

But has some extra packages

H4ad commented 2 years ago

Try removing typescript, esbuild-windows-64 and yarn from your node_modules inside your deploy.zip and then deploy again.

Also, do you have WSL? If so, try deploying inside WSL, I think it's a bug in node-modules-packer on Windows and some issue with the size of the zip.

jmd9019 commented 2 years ago

Try removing typescript, esbuild-windows-64 and yarn from your node_modules inside your deploy.zip and then deploy again.

I removed these files and redeployed now its working

I don't have WSL as my PC SSD is running out of space

H4ad commented 2 years ago

I will try to fix the issue of packing inside Windows in node-modules-packer, but until then, you will need to pack your files manually and remove typescript and esbuild-windows-64.

The issue with the size is probably issue on DO but this thing we can't control.

jmd9019 commented 2 years ago

Sure, I will remove it manually as of now, also can this be also fixed https://github.com/H4ad/serverless-adapter-examples/issues/2#issuecomment-1242977984 node-modules-packer was missing out modules which had folder names starting with @ on my PC

Thanks for the help,

H4ad commented 2 years ago

Hey @jmd9019, I release a new version of @h4ad/node-modules-packer, try running again with it to see if now works.

jmd9019 commented 2 years ago

Hi @H4ad, I tried "@h4ad/node-modules-packer": "^1.2.1" on windows now it's deploying correctly. Thanks for the help.

H4ad commented 2 years ago

Nice man, thanks for using it and reporting this bug.