Deploy failed due to an error in @netlify/plugin-functions-core plugin

highly annoying. Works super on my local, but can’t deploy. This function it complains of used to get build two months ago until last week. So this happened with some Netlfy update.

Error: In file "/opt/build/repo/functions/create-user.js": Cannot find module 'encoding' Require stack:

2:03:42 PM: Build ready to start
2:03:44 PM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6
2:03:44 PM: build-image tag: v3.4.1
2:03:44 PM: buildbot version: cdc66b02d86506251d3343610a77385376c8c035
2:03:44 PM: Fetching cached dependencies
2:03:44 PM: Failed to fetch cache, continuing with build
2:03:44 PM: Starting to prepare the repo for build
2:03:45 PM: No cached dependencies found. Cloning fresh repo
2:03:45 PM: git clone https://github.com/xxxx
2:03:46 PM: Preparing Git Reference refs/heads/master
2:03:49 PM: Different functions path detected, going to use the one specified in the Netlify configuration file: 'functions' versus '' in the Netlify UI
2:03:49 PM: Starting build script
2:03:49 PM: Installing dependencies
2:03:49 PM: Python version set to 2.7
2:03:52 PM: v12.18.0 is already installed.
2:03:53 PM: Now using node v12.18.0 (npm v6.14.4)
2:03:53 PM: Started restoring cached build plugins
2:03:53 PM: Finished restoring cached build plugins
2:03:53 PM: Attempting ruby version 2.7.1, read from environment
2:03:56 PM: Using ruby version 2.7.1
2:03:57 PM: Using PHP version 5.6
2:03:57 PM: 5.2 is already installed.
2:03:57 PM: Using Swift version 5.2
2:03:57 PM: Started restoring cached node modules
2:03:57 PM: Finished restoring cached node modules
2:03:57 PM: Started restoring cached yarn cache
2:03:57 PM: Finished restoring cached yarn cache
2:03:57 PM: Installing yarn at version 1.22.4
2:03:57 PM: Installing Yarn!
2:03:57 PM: > Downloading tarball...
2:03:57 PM: [1/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz --> /tmp/yarn.tar.gz.zSYxfH9xgK
2:03:57 PM:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
2:03:57 PM:                                  Dload  Upload   Total   Spent    Left  Speed
2:03:57 PM:   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
2:03:57 PM: 100    80  100    80    0     0    208      0 --:--:-- --:--:-- --:--:--   208
2:03:58 PM:   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
2:03:58 PM: 100    93  100    93    0     0    123      0 --:--:-- --:--:-- --:--:--   877
2:03:58 PM: 100   643  100   643    0     0    585      0  0:00:01  0:00:01 --:--:--   585
2:03:59 PM: 100 1215k  100 1215k    0     0   764k      0  0:00:01  0:00:01 --:--:--  764k
2:03:59 PM: [2/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz.asc --> /tmp/yarn.tar.gz.zSYxfH9xgK.asc
2:03:59 PM: 100    84  100    84    0     0   3082      0 --:--:-- --:--:-- --:--:--  3082
2:03:59 PM:   0    97    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
2:03:59 PM: 100    97  100    97    0     0   1716      0 --:--:-- --:--:-- --:--:-- 97000
2:03:59 PM: 100   647  100   647    0     0   3500      0 --:--:-- --:--:-- --:--:--  3500
2:03:59 PM: 100  1028  100  1028    0     0   4544      0 --:--:-- --:--:-- --:--:--  4544
2:03:59 PM: > Verifying integrity...
2:03:59 PM: gpg: Signature made Mon 09 Mar 2020 03:52:13 PM UTC using RSA key ID 69475BAA
2:03:59 PM: gpg: Good signature from "Yarn Packaging <yarn@dan.cx>"
2:03:59 PM: gpg: WARNING: This key is not certified with a trusted signature!
2:03:59 PM: gpg:          There is no indication that the signature belongs to the owner.
2:03:59 PM: Primary key fingerprint: 72EC F46A 56B4 AD39 C907  BBB7 1646 B01B 86E5 0310
2:03:59 PM:      Subkey fingerprint: 6D98 490C 6F1A CDDD 448E  4595 4F77 6793 6947 5BAA
2:03:59 PM: > GPG signature looks good
2:03:59 PM: > Extracting to ~/.yarn...
2:03:59 PM: > Adding to $PATH...
2:04:00 PM: > Successfully installed Yarn 1.22.4! Please open another terminal where the `yarn` command will now be available.
2:04:00 PM: Installing NPM modules using Yarn version 1.22.4
2:04:01 PM: yarn install v1.22.4
2:04:02 PM: [1/4] Resolving packages...
2:04:03 PM: [2/4] Fetching packages...
2:04:43 PM: info fsevents@2.1.2: The platform "linux" is incompatible with this module.
2:04:43 PM: info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
2:04:43 PM: info fsevents@1.2.13: The platform "linux" is incompatible with this module.
2:04:43 PM: info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
2:04:43 PM: info fsevents@2.1.3: The platform "linux" is incompatible with this module.
2:04:43 PM: info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
2:04:43 PM: [3/4] Linking dependencies...
2:04:43 PM: warning " > babel-loader@8.1.0" has unmet peer dependency "@babel/core@^7.0.0".
2:04:43 PM: warning " > babel-loader@8.1.0" has unmet peer dependency "webpack@>=2".
2:04:43 PM: warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
2:04:43 PM: warning " > @babel/plugin-proposal-class-properties@7.12.1" has unmet peer dependency "@babel/core@^7.0.0-0".
2:04:43 PM: warning " > @babel/plugin-proposal-object-rest-spread@7.12.1" has unmet peer dependency "@babel/core@^7.0.0-0".
2:04:43 PM: warning " > @babel/plugin-transform-object-assign@7.12.1" has unmet peer dependency "@babel/core@^7.0.0-0".
2:05:03 PM: [4/4] Building fresh packages...
2:05:06 PM: Done in 64.25s.
2:05:06 PM: NPM modules installed using Yarn
2:05:07 PM: Started restoring cached go cache
2:05:07 PM: Finished restoring cached go cache
2:05:07 PM: go version go1.14.4 linux/amd64
2:05:07 PM: go version go1.14.4 linux/amd64
2:05:07 PM: Installing missing commands
2:05:07 PM: Verify run directory
2:05:09 PM: ​
2:05:09 PM: ┌─────────────────────────────┐
2:05:09 PM: │        Netlify Build        │
2:05:09 PM: └─────────────────────────────┘
2:05:09 PM: ​
2:05:09 PM: ❯ Version
2:05:09 PM:   @netlify/build 5.0.3
2:05:09 PM: ​
2:05:09 PM: ❯ Flags
2:05:09 PM:   deployId: 5f995e1dba52750008078af0
2:05:09 PM:   mode: buildbot
2:05:09 PM: ​
2:05:09 PM: ❯ Current directory
2:05:09 PM:   /opt/build/repo
2:05:09 PM: ​
2:05:09 PM: ❯ Config file
2:05:09 PM:   /opt/build/repo/netlify.toml
2:05:09 PM: ​
2:05:09 PM: ❯ Context
2:05:09 PM:   production
2:05:11 PM: ​
2:05:11 PM: ┌───────────────────────────────────┐
2:05:11 PM: │ 1. Build command from Netlify app │
2:05:11 PM: └───────────────────────────────────┘
2:05:11 PM: ​
2:05:11 PM: $ npm run build
2:05:11 PM: > truly-agency-saas@1.0.0 build /opt/build/repo
2:05:11 PM: > run-p build:**
2:05:12 PM: > truly-agency-saas@1.0.0 build:lambda /opt/build/repo
2:05:12 PM: > netlify-lambda build src/lambda
2:05:12 PM: > truly-agency-saas@1.0.0 build:app /opt/build/repo
2:05:12 PM: > react-scripts build
2:05:13 PM: netlify-lambda: Building functions
2:05:15 PM: Creating an optimized production build...
2:05:44 PM: Compiled successfully.
2:05:44 PM: 
2:05:44 PM: File sizes after gzip:
2:05:44 PM:   49.63 KB  build/static/js/2.79ebf224.chunk.js
2:05:44 PM:   1.35 KB   build/static/js/main.7af9b4b5.chunk.js
2:05:44 PM:   778 B     build/static/js/runtime-main.bf19a910.js
2:05:44 PM:   510 B     build/static/css/main.63d4069d.chunk.css
2:05:44 PM: The project was built assuming it is hosted at /.
2:05:44 PM: You can control this with the homepage field in your package.json.
2:05:44 PM: The build folder is ready to be deployed.
2:05:44 PM: You may serve it with a static server:
2:05:44 PM:   yarn global add serve
2:05:44 PM:   serve -s build
2:05:44 PM: Find out more about deployment here:
2:05:44 PM:   bit.ly/CRA-deploy
2:14:13 PM: Hash: d89cd407d9a0418e7f89
2:14:13 PM: Version: webpack 4.44.2
2:14:13 PM: Time: 539488ms
2:14:13 PM: Built at: 10/28/2020 12:14:13 PM
2:14:13 PM:                             Asset      Size  Chunks             Chunk Names
2:14:13 PM:                    create-user.js  7.07 MiB       0  [emitted]  create-user
2:14:13 PM:                    delete-user.js  7.07 MiB       1  [emitted]  delete-user
2:14:13 PM: get-organisation-channel-stats.js  4.56 MiB       2  [emitted]  get-organisation-channel-stats
2:14:13 PM:                          hello.js  1.12 KiB       3  [emitted]  hello
2:14:13 PM:         list-all-organisations.js  4.56 MiB       4  [emitted]  list-all-organisations
2:14:13 PM:                 list-all-users.js  3.05 MiB       5  [emitted]  list-all-users
2:14:13 PM:                    save-config.js  4.56 MiB       6  [emitted]  save-config
2:14:13 PM:                          world.js  1.16 KiB       7  [emitted]  world
2:14:13 PM: Entrypoint create-user = create-user.js
2:14:13 PM: Entrypoint delete-user = delete-user.js
2:14:13 PM: Entrypoint get-organisation-channel-stats = get-organisation-channel-stats.js
2:14:13 PM: Entrypoint hello = hello.js
2:14:13 PM: Entrypoint list-all-organisations = list-all-organisations.js
2:14:13 PM: Entrypoint list-all-users = list-all-users.js
2:14:13 PM: Entrypoint save-config = save-config.js
2:14:13 PM: Entrypoint world = world.js
2:14:13 PM:    [0] /opt/build/repo/node_modules/googleapis-common/build/src/index.js 2.3 KiB {0} {1} {2} {4} {6} [built]
2:14:13 PM:   [33] /opt/build/repo/node_modules/google-auth-library/build/src/index.js 2.78 KiB {0} {1} {2} {4} {5} {6} [built]
2:14:13 PM:  [202] /opt/build/repo/node_modules/googleapis/build/src/apis/abusiveexperiencereport/v1.js 4.91 KiB {0} {1} {2} {4} {6} [built]
2:14:13 PM:  [508] /opt/build/repo/node_modules/axios/index.js 40 bytes {0} {1} {2} {4} {6} [built]
2:14:13 PM:  [509] /opt/build/repo/node_modules/firebase-admin/lib/index.js 1.36 KiB {0} {1} {5} [built]
2:14:13 PM:  [630] /opt/build/repo/node_modules/googleapis/build/src/index.js 54.8 KiB {0} {1} {2} {4} {6} [built]
2:14:13 PM: [1286] /opt/build/repo/node_modules/google-spreadsheet/index.js 410 bytes {2} {4} {6} [built]
2:14:13 PM: [1291] ./create-user.js 4.58 KiB {0} [built]
2:14:13 PM: [1292] ./delete-user.js 3.96 KiB {1} [built]
2:14:13 PM: [1293] ./get-organisation-channel-stats.js 3.85 KiB {2} [built]
2:14:13 PM: [1294] ./hello.js 167 bytes {3} [built]
2:14:13 PM: [1295] ./list-all-organisations.js 3.7 KiB {4} [built]
2:14:13 PM: [1296] ./list-all-users.js 3.37 KiB {5} [built]
2:14:13 PM: [1297] ./save-config.js 3.97 KiB {6} [built]
2:14:13 PM: [1298] ./world.js 219 bytes {7} [built]
2:14:13 PM:     + 1284 hidden modules
2:14:13 PM: WARNING in /opt/build/repo/node_modules/hash-stream-validation/index.js
2:14:13 PM: Module not found: Error: Can't resolve 'fast-crc32c' in '/opt/build/repo/node_modules/hash-stream-validation' @ /opt/build/repo/node_modules/hash-stream-validation/index.js
2:14:13 PM:  @ /opt/build/repo/node_modules/@google-cloud/storage/build/src/file.js
2:14:13 PM:  @ /opt/build/repo/node_modules/@google-cloud/storage/build/src/index.js
2:14:13 PM:  @ /opt/build/repo/node_modules/firebase-admin/lib/storage/storage.js
2:14:13 PM:  @ /opt/build/repo/node_modules/firebase-admin/lib/firebase-namespace.js
2:14:13 PM:  @ /opt/build/repo/node_modules/firebase-admin/lib/default-namespace.js
2:14:13 PM:  @ /opt/build/repo/node_modules/firebase-admin/lib/index.js
2:14:13 PM:  @ ./create-user.js
2:14:14 PM: ​
2:14:14 PM: (build.command completed in 9m 3.5s)
2:14:14 PM: ​
2:14:14 PM: ┌────────────────────────────────────────────────────────┐
2:14:14 PM: │ 2. onBuild command from @netlify/plugin-functions-core │
2:14:14 PM: └────────────────────────────────────────────────────────┘
2:14:14 PM: ​
2:14:14 PM: Packaging Functions from functions directory:
2:14:14 PM:  - create-user.js
2:14:14 PM:  - delete-user.js
2:14:14 PM:  - get-organisation-channel-stats.js
2:14:14 PM:  - hello.js
2:14:14 PM:  - list-all-organisations.js
2:14:14 PM:  - list-all-users.js
2:14:14 PM:  - save-config.js
2:14:14 PM:  - world.js
2:15:52 PM: ​
2:15:52 PM: ┌────────────────────────────────────────────────────────┐
2:15:52 PM: │ Plugin "@netlify/plugin-functions-core" internal error │
2:15:52 PM: └────────────────────────────────────────────────────────┘
2:15:52 PM: ​
2:15:52 PM:   Error message
2:15:52 PM:   Error: In file "/opt/build/repo/functions/create-user.js": Cannot find module 'encoding'
2:15:52 PM:   Require stack:
2:15:52 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/resolve.js
2:15:52 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/dependencies.js
2:15:52 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
2:15:52 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/index.js
2:15:52 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/logic.js
2:15:52 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/load.js
2:15:52 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/main.js
2:15:52 PM: ​
2:15:52 PM:   Plugin details
2:15:52 PM:   Package:        @netlify/plugin-functions-core
2:15:52 PM:   Version:        5.0.3
2:15:52 PM:   Repository:     git+https://github.com/netlify/build.git
2:15:52 PM:   npm link:       https://www.npmjs.com/package/@netlify/build
2:15:52 PM:   Report issues:  https://github.com/netlify/build/issues
2:15:52 PM: ​
2:15:52 PM:   Error location
2:15:52 PM:   In "onBuild" event in "@netlify/plugin-functions-core" from core
2:15:52 PM:       at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
2:15:52 PM:       at Function.resolve (internal/modules/cjs/helpers.js:83:19)
2:15:52 PM:       at resolvePathFollowSymlinks (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/resolve.js:62:18)
2:15:52 PM:       at resolvePackageFallback (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/resolve.js:74:24)
2:15:52 PM:       at resolvePackage (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/resolve.js:33:27)
2:15:52 PM: ​
2:15:52 PM:   Error properties
2:15:52 PM:   { code: 'MODULE_NOT_FOUND' }
2:15:52 PM: ​
2:15:52 PM:   Resolved config
2:15:52 PM:   build:
2:15:52 PM:     command: npm run build
2:15:52 PM:     commandOrigin: ui
2:15:52 PM:     functions: /opt/build/repo/functions
2:15:52 PM:     publish: /opt/build/repo/build
2:15:52 PM:   redirects:
2:15:52 PM:     - from: /*      status: 200      to: /index.htmlCaching artifacts
2:15:52 PM: Started saving node modules
2:15:52 PM: Finished saving node modules
2:15:52 PM: Started saving build plugins
2:15:52 PM: Finished saving build plugins
2:15:52 PM: Started saving yarn cache
2:15:52 PM: Finished saving yarn cache
2:15:52 PM: Started saving pip cache
2:15:52 PM: Finished saving pip cache
2:15:52 PM: Started saving emacs cask dependencies
2:15:52 PM: Finished saving emacs cask dependencies
2:15:52 PM: Started saving maven dependencies
2:15:52 PM: Finished saving maven dependencies
2:15:52 PM: Started saving boot dependencies
2:15:52 PM: Finished saving boot dependencies
2:15:52 PM: Started saving go dependencies
2:15:52 PM: Finished saving go dependencies
2:15:56 PM: Build failed due to an internal system error: Build script returned non-zero exit code: 4
2:15:56 PM: Failing build: Failed to build site
2:15:56 PM: Failed during stage 'building site': Build script returned non-zero exit code: 4
2:15:56 PM: Finished processing build request in 12m11.963688668s

Quite likely, something useful was cached and, well… now there’s no cache!

There’s a hearty discussion over here – hopefully this steers you in the right direction :slight_smile:

thanks @Pie for your input. The solution some had in the linked disussion, did not help me (encoded as dependency)
Also, something useful was in cache and now there is no cache. What helps here?
Seems like problem is with npm versions to me, but can’t really affect this

This can happen is cached versions all work in harmony and then the cache is dropped. Have you considered the following points from that topic?

Added “encoding” to package.json

Worked for me.
NB! Had to remove package-lock as well

But npm install encoding and then rebuilding worked.

I have installed encoding as a dependency and no luck with removing package-lock

That error usually crops up when using node-fetch. It doesn’t do it often anymore but the simplest solution is to switch the package for isomorphic-fetch. The good thing is the syntax/api for is the same so it just a matter of changing the require statement.

Let me know if that helps.

I don’t use node-fetch at all

Hey @Mik-A,
Really sorry to have dropped the ball here! For quicker response times going forward, please open a ticket in our helpdesk by emailing support@netlify.com from an email address associated with your Pro account and we’ll get back to you there.

For now, we did take a look at your deploys and are seeing that your most recent deploy shows a different error than the one you wrote in about: https://app.netlify.com/sites/adoring-edison-7cf4c8/deploys/5f9aa5d9cd3e510007b85943

4:23:04 AM: > netlify-lambda build src/lambda
4:23:05 AM: netlify-lambda: Building functions
4:23:06 AM: Creating an optimized production build...
4:27:04 AM: The build failed because the process exited too early. This probably means the system ran out of memory or someone called `kill -9` on the process.
4:27:04 AM: npm ERR! code ELIFECYCLE
4:27:04 AM: npm ERR! errno 1
4:27:04 AM: npm ERR! truly-agency-saas@1.0.0 build:app: `CI= react-scripts build`
4:27:04 AM: npm ERR! Exit status 1
4:27:04 AM: npm ERR!
4:27:04 AM: npm ERR! Failed at the truly-agency-saas@1.0.0 build:app script.

Would you be willing to deploy with the CLI instead of netlify-lambda? netlify-lambda seems to be causing significant deploy issues here. If not, another option is to cat out the npm debug log. You’d do that by changing your build command to npm run build ; cat /opt/buildhome/.npm/_logs/2020*debug.log ; sleep 300 ; false. npm run build will fail, but hopefully we’d get more output about what went wrong.

hmm, not sure where to change as per your suggestion. Toml has “npm run build” and package.json has that too. However. I don’t know how to link my local folder with netlify. it asks for an ID but there is no such things.
if I use netlify link -name my-site-name’ It looks for something in github and complains no such bla bla

Sorry for that slow followup; Jen’s been out. What she was saying is you’ll want to change the command in the toml from what it is now to:

npm run build ; cat /opt/buildhome/.npm/_logs/2020*debug.log ; sleep 300 ; false

and that should show the npm error log in the deploy logs to help you diagnose the cause of the proglem.

ok i get it it now. However did not find anything new there. But found out that Netlify updates seem to have stopped supporting a few npm packages.

  • google-spreadsheet
  • googleapis
  • firebase-admin

at least when used in lambda functions with netlify-cli

What updates are you expecting exactly? There are valid configurations in which we do not control your function dependencies but rather you do; also, our dependency handling typically does not “update” packages unless your package.json or yarn.lock changes - are you doing that, or just expecting us to always fetch “latest” of each package on each build? Also, could you tell us how you are shipping your functions, from among the 3 methods shown here?