Plugin "@netlify/plugin-functions-core" internal error

Not sure if this is the right place for this. This is taken directly from the “netlify deploy logs”. I’m currently not able to deploy needed production changes.

error description
2. onBuild command from @netlify/plugin-functions-core

Packaging Functions from lambda directory:

  • myfunction.js

    Plugin “@netlify/plugin-functions-core” internal error

    Error message
    Error: In file “/opt/build/repo/lambda/myfunction.js”: Cannot find module ‘encoding’
    Require stack:
  • /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
  • /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
  • /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
  • /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/index.js
  • /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/logic.js
  • /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/load.js
  • /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/main.js

    Plugin details
    Package: @netlify/plugin-functions-core
    Version: 5.0.0
    Repository: git+https://github.com/netlify/build.git
    npm link: https://www.npmjs.com/package/@netlify/build
    Report issues: https://github.com/netlify/build/issues

    Error location
    In “onBuild” event in “@netlify/plugin-functions-core” from core
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)

After further research this seems to be an open issue for “Zip it and ship it”

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

thanks, dean. I’ll check i with Mickael in a few days if he doesn’t comment on the issue sooner so we can understand when this come through.

I have this issue too:

@perry I suspect this is actually pretty serious, since I think it might affect deployments across all Netlify.

– Edit: It appears to be related to @netlify/plugin-functions-core blowing up if there is a conditional dependency in the function

Of course, it could just be a me issue, but given that the error is being reported from inside a Netlify build process, I don’t think so

– Edit: given the above, it won’t affect all users

┌────────────────────────────────────────────────────────┐
│ 2. onBuild command from @netlify/plugin-functions-core │
└────────────────────────────────────────────────────────┘
​
Packaging Functions from functions directory:
 - image.js
​
┌────────────────────────────────────────────────────────┐
│ Plugin "@netlify/plugin-functions-core" internal error │
└────────────────────────────────────────────────────────┘
​
  Error message
  Error: In file "/opt/build/repo/functions/image.js": Cannot find module 'encoding'
  Require stack:
  - /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
  - /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
  - /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
  - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/index.js
  - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/logic.js
  - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/load.js
  - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/main.js
​
  Plugin details
  Package:        @netlify/plugin-functions-core
  Version:        5.0.0
  Repository:     git+https://github.com/netlify/build.git
  npm link:       https://www.npmjs.com/package/@netlify/build
  Report issues:  https://github.com/netlify/build/issues
​
  Error location
  In "onBuild" event in "@netlify/plugin-functions-core" from core
      at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
      at Function.resolve (internal/modules/cjs/helpers.js:83:19)
      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)
      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)
      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)
​
  Error properties
  { code: 'MODULE_NOT_FOUND' }
​
  Resolved config
  build:
    command: npm run build
    commandOrigin: config
    environment:
      - UNSPLASH_API
    functions: /opt/build/repo/functions
    publish: /opt/build/repo/public
Caching artifacts

Point of reference: My lambda function contains no conditional dependency.

1 Like

I was using node-fetch, which I had no idea did have a conditional dependency until I read about it in one of the issue comments. I replaced that with http.get and was able to deploy successfully

The simple function I wrote does not explicitly use node-fetch, but I see the build process creates a lambda that does.
I don’t think I can change that easily. A grep of the project shows a whole series of node_modules that use node-fetch.

1 Like

After some research I realized the simple require in my (Netlify) function is for a 3rd party library that DOES include node-fetch. For that library, node-fetch is its only dependency. I REALLY don’t want to try taking on modifying that library.

Yeah. I debated with myself: spend the money to fix it, or wait for Netlify to fix it. Decided I had more money than time in this situation

I’ve got other rabbit holes needing attention, but this one is making my client unhappy.

1 Like

I don’t know if this would help you or maybe someone else who finds this thread, but this is the code that I used to replace node-fetch. It’s in TypeScript.

`apiPromise( ).then(data => doStuffWith(data))

Might save some time.