question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
erezrokahcommented, Feb 5, 2021

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

0reactions
MisterJimsoncommented, Aug 4, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best practices for working with AWS Lambda functions
Lambda purges idle connections over time. Attempting to reuse an idle connection when invoking a function will result in a connection error.
Read more >
Error: Could not find “encoding” module in file, Netlify function
I'm using netlify-lambda build src/functions to bundle the functions. ... zip your function but that's failing because the encoding dependency isn't there.
Read more >
Error: Cannot find module while using Netlify lambda functions ...
You should only have one package.json in the base directory . If that does not work then try to delete package-lock.json and try...
Read more >
Cleanup the node_modules for a lighter Lambda Function
Any nodejs project carries a bulky folder - the node_modules - that carries all the modules and dependencies that the application would need...
Read more >
How to migrate your Node.js Lambda functions to AWS SDK v3
There are two main reasons why the new SDK enables you to deploy smaller bundle sizes: You only require (or import ) the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found