redwood icon indicating copy to clipboard operation
redwood copied to clipboard

[Bug?]: nftPack: undefined is not a function

Open jayhyp opened this issue 9 months ago • 9 comments

What's not working?

Deploying Redwood API to Serverless Deploy using the following command fails: yarn rw deploy serverless --stage prod --side api

Error: [COMPLETED] Checking if Serverless framework is installed... [STARTED] Building api... ❯ Generating Prisma Client... ✔ Generating Prisma Client... ❯ Verifying graphql schema... ✔ Verifying graphql schema... ❯ Building API... ✔ Building API... [COMPLETED] Building api... [STARTED] Packing Functions... [FAILED] undefined is not a function undefined is not a function

This is the function:

function nftPack() { const filesToBePacked = (0, import_files.findApiDistFunctions)(); return Promise.all(filesToBePacked.map(exports.packageSingleFunction)); }

If you change the map function and remove the exports. so it just references the packageSingleFunction then it works.

How do we reproduce the bug?

yarn rw deploy serverless --stage prod --side api

What's your environment? (If it applies)

No response

Are you interested in working on this?

  • [ ] I'm interested in working on this

jayhyp avatar Apr 29 '24 10:04 jayhyp

Thanks for raising this @jayhyp!

@ahaywood I'll assign to you as I believe serverless is a deprecated deployment provider, and unsure where this stands in priority.

dac09 avatar Apr 30 '24 09:04 dac09

@jayhyp Can you confirm that you have files in api/src/services and/or api/src/functions? I.e. have you created any API endpoints or functions yet? If not, that would be the reason you're seeing the error -> no files exist to pack.

thedavidprice avatar Apr 30 '24 16:04 thedavidprice

This happens to us as well after an rw upgrade to 7.5. Working perfectly fine on 6.x. No other code changes apart from the upgrade, also using the serverless deployment method. Have reverted to 6.x again for now - but will investigate further once time allows.

As a sidenote - this worked fine on ~7.2 (but then hit the Auth issue that was resolved).

jwwisgerhof avatar May 12 '24 09:05 jwwisgerhof

@jwwisgerhof Thanks for the additional information. Just to confirm – you're saying something changed between 7.2 and 7.5 that broke Serverless?

Tobbe avatar May 14 '24 07:05 Tobbe

@Tobbe Yes, just checked and last I tried to upgrade to RW was 7.2.0-rc.53. The deployment worked correctly but we ran into the Authorization header issue, forcing a downgrade to 6.x.

jwwisgerhof avatar May 14 '24 07:05 jwwisgerhof

@Tobbe Yes, just checked and last I tried to upgrade to RW was 7.2.0-rc.53. The deployment worked correctly but we ran into the Authorization header issue, forcing a downgrade to 6.x.

HI @jwwisgerhof re "the Authorization header issue" is that the lower vs uppercase issue to recognizing "Authorization"?

That was fixed in https://github.com/redwoodjs/redwood/releases/tag/v7.3.2

dthyresson avatar May 15 '24 11:05 dthyresson

Hi @dthyresson - yes, that is the one. I am aware it was fixed, which is why I tried the upgrade to RW 7 again. It is relevant to this ticket only in that it narrows the window in which this bug was introduced to somewhere between RW7.2.0-rc.53 and current version.

Packaging of functions worked in 7.2.0-rc.53 but does not in 7.5.x (same codebase).

jwwisgerhof avatar May 16 '24 01:05 jwwisgerhof

Thanks for the extra detail @jwwisgerhof -- do you think I can reproduce this with any small new RW project and the arn rw deploy serverless --stage prod --side api command ?

Looking at the code https://github.com/redwoodjs/redwood/blob/7e1cb8a8c0c70d0fde029cfb5ace0fe9679e00c2/packages/cli/src/commands/deploy/serverless.js#L86 , I see the following:

    {
      title: 'Packing Functions...',
      enabled: () => sides.includes('api'),
      task: async () => {
        // Dynamically import this function
        // because its dependencies are only installed when `rw setup deploy serverless` is run
        const { nftPack } = await import('./packing/nft.js')

        await nftPack()
      },
    },

Maybe rw setup deploy serverless needs to be re-run in 7+?

Could we see if the following packages have been installed in your project?

https://github.com/redwoodjs/redwood/blob/7e1cb8a8c0c70d0fde029cfb5ace0fe9679e00c2/packages/cli/src/commands/setup/deploy/providers/serverless.js#L52

Seems like it cannot find packing/nft.js to import.

dthyresson avatar May 17 '24 16:05 dthyresson

Thanks @dthyresson - can confirm that @vercel/nft is in the lock file and the file system. Easier way to reproduce is by using the --pack-only arg. IE: yarn rw deploy sls --stage production --side api --pack-only.

Let me have a look later today to see if I can find out more information now that I know where to look.

jwwisgerhof avatar May 18 '24 00:05 jwwisgerhof