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

fix: serverless failing #162

Merged
merged 8 commits into from
May 30, 2024

Conversation

andreabadesso
Copy link
Collaborator

@andreabadesso andreabadesso commented Apr 25, 2024

Motivation

Serverless was failing to package because of multiple issues related to the new yarn workspaces monorepo structure:

  1. It wasn't able to find the common module:
Error: Cannot find module './@wallet-service/common/package.json'

Upon investigation, I found out that this was happening because it yarn workspaces symlinks internal modules to the package's node_modules and serverless-monorepo was cleaning it

The fix for this issue was adding it as a peer dependency, which actually copied the dependency to the node_modules folder and also adding it to be parsed by the ts-loader

  1. Peer dependencies were not being transpiled by webpack

This is a weird one, but after we solved the issue with the common module, the package was failing in runtime because of errors on the imports

I wasn't to dive deep into why this was the case, but moving the peer dependencies to be dependencies fixed this issue.

My suggestion is to move on with this PR because it is stopping us from fixing a bug affecting our production server (NFT metadata is not being created on S3) and investigate in a KTLO in the near future.

The side effect is only that yarn install will take a little longer because it will not hoist the peer dependencies into the root package.

Acceptance Criteria

  • The wallet-service should be able to be packaged and deployed using the common module
  • Dependencies should be properly transpiled by webpack

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged
  • Make sure either the unit tests and/or the QA tests are capable of testing the new features
  • Make sure you do not include new dependencies in the project unless strictly necessary and do not include dev-dependencies as production ones. More dependencies increase the possibility of one of them being hijacked and affecting us.

@andreabadesso andreabadesso changed the base branch from master to refactor/common-project April 25, 2024 15:43
@pedroferreira1 pedroferreira1 added the bug Something isn't working label Apr 26, 2024
@pedroferreira1 pedroferreira1 marked this pull request as draft April 26, 2024 16:49
@andreabadesso andreabadesso force-pushed the fix/serverless-failing branch 2 times, most recently from 6da1cd1 to 5ae61b7 Compare April 30, 2024 16:41
@andreabadesso andreabadesso marked this pull request as ready for review April 30, 2024 16:41
@andreabadesso andreabadesso force-pushed the refactor/common-project branch from c19c2c3 to 16ba61f Compare April 30, 2024 16:42
@andreabadesso andreabadesso force-pushed the fix/serverless-failing branch from 5ae61b7 to fe06242 Compare April 30, 2024 16:43
@andreabadesso andreabadesso force-pushed the refactor/common-project branch from 16ba61f to 9d84734 Compare May 1, 2024 17:57
@andreabadesso andreabadesso force-pushed the fix/serverless-failing branch from fe06242 to 9567898 Compare May 1, 2024 17:57
.yarnrc.yml Show resolved Hide resolved
packages/wallet-service/src/api/wallet.ts Show resolved Hide resolved
@@ -24,7 +24,9 @@ module.exports = {
filename: '[name].js',
},
target: 'node',
externals: [nodeExternals()],
externals: [nodeExternals({
allowlist: [new RegExp("@wallet-service/common*")],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this?

Copy link
Collaborator Author

@andreabadesso andreabadesso May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bundle gets too big if we allow webpack to bundle all dependencies so we remove them from the bundle (they get loaded in runtime)

But we can't do this with the common module, otherwise it would not be seen by the serverless-monorepo package

Copy link

@tuliomir tuliomir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I agree with your suggestion to move on with this PR and investigate the peer dependencies issue through a KTLO.

My recommendation would be to add the issue number to this PR description now, so that it's easier to track these changes in the future.

package.json Show resolved Hide resolved
@andreabadesso andreabadesso force-pushed the refactor/common-project branch from 9d84734 to 25261a1 Compare May 4, 2024 00:53
@andreabadesso andreabadesso force-pushed the fix/serverless-failing branch from 9567898 to 4bbbf6b Compare May 27, 2024 16:41
@andreabadesso andreabadesso force-pushed the fix/serverless-failing branch from c2fe235 to 8deea8b Compare May 29, 2024 21:35
@andreabadesso andreabadesso force-pushed the fix/serverless-failing branch from 8deea8b to b21d3f3 Compare May 29, 2024 21:35
@andreabadesso andreabadesso merged commit fab1c25 into refactor/common-project May 30, 2024
1 check passed
@andreabadesso andreabadesso deleted the fix/serverless-failing branch May 30, 2024 00:11
andreabadesso added a commit that referenced this pull request May 30, 2024
* chore: added common package

* chore: using wallet-lib from daemon resolution

* chore: installed shared dependencies on root project, using peerDependencies

* refactor: using addAlert method from common utils

* chore: updated package.json with missing deps

* refactor: using types from commons on wallet-service

* chore: re-added sequelize to root

* refactor: removed isNftAutoReviewEnabled from services

* tests: mocked assertEnv

* tests: mocked assertEnv on integration tests

* chore: removed nft utils

* refactor: removed old addAlerts from the wallet-service package

* chore: wallet-lib is now a peerDependency in wallet-service package

* refactor: logger is now a required param in addAlert, refactored all methods in wallet-service package

* docs: added missing hathor header

* refactor: invalid type for metadata on addAlert

* tests: passing mocked logger

* chore: updated gitignore to ignore env files

* chore: revert eslint package updates

* refactor: using types from commons on wallet-service

* refactor: removed unused commented line

* chore: missing package in daemon

* refactor: using transaction type from common

* refactor: bitcoinjs is not a shared dep

* chore: added a comment explaining that logger is a param temporarily

* refactor: removed default from metadata

* chore: lint fixes and package ordering

* feat: call onNewNftEvent when a new NFT tx is received (#150)

* feat: added nft utils

* tests: added tests for common utils

* chore: added common module to CI

* refactor: moved used types to common package

* tests: removed nft utils

* tests: fixed nft tests on txProcessor

* tests: mocking network on getconfig

* tests: fixed nft tests on txProcessor

* refactor: passing logger to invoke nft handler

* refactor: no need to ignore ts

* chore: removed jest script, instead using only test

* chore: added hathor header

* refactor: using common utils on txProcessor

* tests: nft utils using old syntax

* tests: skipped txProcessor tests

* tests: fixed txProcessor tests

* refactor: using isAuthority from common utils

* refactor: using isAuthority from common types

* refactor: using assertEnvVariablesExistance from common project

* refactor: getting CREATE_NFT_MAX_RETRIES from env

* docs: updated docstrings on nft utils

* chore: removed events/nftCreationTx.ts

* refactor: invalid import locations

* refactor: remove unused lambdas (#155)

* tests: fixed nft tests on txProcessor

* refactor: removed all methods related to the old wallet-service txProcessor

* tests: fixed failing test

* fix: serverless failing (#162)

* refactor: logger is now a required param in addAlert, refactored all methods in wallet-service package

* chore: changed module resolution and several package locks

* chore: added common library to externals whitelist and whitelisted it in tsloader

* chore: wallet-service common package moved from direct path to workspace

* chore: added common as a peer dependency and restored peer dependencies

* chore: removed peer dependencies as they were not working with serverless-monorepo

* chore: added comment on hoisting limits

* chore: added comment explaining externals in webpack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants