Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Lambda Functions bundling failed due to non required 'encoding' module #309

Open
bomzj opened this issue Jan 26, 2021 · 9 comments
Open

Comments

@bomzj
Copy link

bomzj commented Jan 26, 2021

I have issues with deployment on Netlify with dependency ‘encoding’ which is not used by my project explicitly. I discovered that once I added faunadb dependency to my project. npm run build of vue-cli works fine locally, but fails on Netlify.

Configuration

netlify.toml

[build]
  functions = "lambda"
  publish = "dist"

package.json

"scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "lambda-serve": "netlify-lambda serve src/lambda"
  },
  "dependencies": {
    "@tailwindcss/custom-forms": "^0.2.1",
    "axios": "^0.21.0",
    "axios-extensions": "^3.1.3",
    "core-js": "^3.6.4",
    "faunadb": "^4.0.0",
    "form-data": "^3.0.0",
    "fuse.js": "^6.4.5",
    "node-sass": "^4.14.1",
    "qs": "^6.9.6",
    "sass-loader": "^8.0.2",
    "tailwindcss": "^1.9.6",
    "vue": "^2.6.11",
    "vue-js-modal": "^2.0.0-rc.3"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.3.0",
    "@vue/cli-plugin-eslint": "~4.3.0",
    "@vue/cli-service": "~4.3.0",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.2.2",
    "node-fetch": "^2.6.0",
    "postcss-import": "^12.0.1",
    "vue-cli-plugin-netlify-lambda": "~0.1.1",
    "vue-template-compiler": "^2.6.11"
  },

Environment Info

  System:
    OS: Windows 10 10.0.18363
    CPU: (8) x64 AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx
    Memory: 2.05 GB / 6.92 GB
  Binaries:
    Node: 13.9.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.13.7 - C:\Program Files\nodejs\npm.CMD

Deploy logs

3:46:14 PM: ────────────────────────────────────────────────────────────────
3:46:14 PM:   Dependencies installation error                               
3:46:14 PM: ────────────────────────────────────────────────────────────────
3:46:14 PM: ​
3:46:14 PM:   Error message
3:46:14 PM:   A Netlify Function failed to require one of its dependencies.
3:46:14 PM:   If the dependency is a Node module, please make sure it is present in the site's top-level "package.json".
  If it is a local file instead, please make sure the file exists and its filename is correctly spelled.
3:46:14 PM: ​
3:46:14 PM:   In file "/opt/build/repo/lambda/currency-rates.js"
3:46:14 PM:   Cannot find module 'encoding'
3:46:14 PM:   Require stack:
3:46:14 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/node_dependencies/resolve.js
3:46:14 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/node_dependencies/index.js
3:46:14 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/main.js
3:46:14 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/index.js
3:46:14 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/commands/get.js
3:46:14 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/core/main.js
3:46:14 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/core/bin.js
@ehmicky
Copy link
Contributor

ehmicky commented Jan 26, 2021

Hi @bomzj,

Thanks for reporting this.
This appears to be the same issue described in #135. Please let us know if the information in that issue are solving your problem.

@ehmicky ehmicky transferred this issue from netlify/build Jan 26, 2021
@bomzj
Copy link
Author

bomzj commented Jan 26, 2021

This appears to be the same issue described in #135. Please let us know if the information in that issue are solving your problem.

Sorry, I didn't find a solution within the #135 ticket. As far as I know a fix is just to add encoding module to package.json. But it looks like workaround. Is there something that can be done on Netlify side e.g. to fix this issue in the Netlify build pipeline?

@lambrospetrou
Copy link

lambrospetrou commented Feb 5, 2021

I also hit this issue as well, just by importing the new AWS SDK v3 for S3 (@aws-sdk/s3-request-presigner, @aws-sdk/client-s3), and somehow zip-it-and-ship-it tries to resolve the react-native package, which is not used anywhere!

I even customised my Next.js webpack configuration to bundle/minify my serverless functions as well, but this module still tries to resolve npm packages and do its own bundling.

Is there a way I can skip the bundling of the JS files for serverless functions, and just do the rest (e.g. zipping, etc.) using the files I provide?

I would prefer to do the bundling on my own rather than installing react-native or whatever other npm package ends up (incorrectly) being resolved by this package. At least until the resolution is in some way fixed...

I have also gone through #68 but I don't see any solution there, apart from some proposals.

edit: I managed now to bundle the serverless functions separately directly with webpack (not through Next.js) and it seems that it works, and it does not try to resolve packages.

@erezrokah
Copy link
Contributor

erezrokah commented Feb 5, 2021

Is there a way I can skip the bundling of the JS files for serverless functions, and just do the rest (e.g. zipping, etc.) using the files I provide?

Hi @lambrospetrou yes you can! This is somehow documents here (not clear enough though):
https://github.com/netlify/zip-it-and-ship-it#zipfunctionssrcfolder-destfolder-options

.zip archives with Node.js already ready to upload to AWS Lambda.

If your functions are already packed into .zip files they be deployed as is.

@lambrospetrou
Copy link

lambrospetrou commented Feb 5, 2021

This is somehow documents here (not clear enough though)
.zip archives with Node.js already ready to upload to AWS Lambda

Cool, I actually looked at the docs but missed that line. I found out about the ready .zip bundles by searching in Google and reading others' posts doing it.

I suggest adding this information in the official Netlify docs along with conventions like naming, similar to the unbundled function deploys section since for more advanced cases, this is really the only way to go.
If you could point me where the docs are (if they are open source) I could attempt to contribute as well.

Thanks

@erezrokah
Copy link
Contributor

Thanks @lambrospetrou, docs are not open source. I'll open an issue for our docs team per you great suggestion :)

@imamhanafi1998
Copy link

excuse me. @erezrokah , i still confused how to do it. can you just show me the repo? please

@erezrokah
Copy link
Contributor

Hi @imamhanafi1998, can you describe the problem you're experiencing? I'm not sure what repo you are referring to

@MisterJimson
Copy link

I'm seeing a similar problem.

Error message
5:59:05 PM:   A Netlify Function failed to require one of its dependencies.
5:59:05 PM:   Please make sure it is present in the site's top-level "package.json".
​
5:59:05 PM:   In file "/opt/build/repo/netlify/functions/next_careers/next_careers.js"
5:59:05 PM:   Cannot find module '@react-native-async-storage/async-storage'

Its not a React Native project, and we don't use that module.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants