Netlify lambda deployment options

When deploying app with lambda functions, netlify dev and netlify build/deploy yield different results.

Site: https://632e15b5fbe18d58948fa7e8--jprime.netlify.app/
Deploy status page: Netlify App
lambda URL: https://632e15b5fbe18d58948fa7e8--jprime.netlify.app/.netlify/functions/primes?z=57

full build and deploy (–debug) logs at bottom

I posted about this yesterday but have made some changes and now I see different results.

Formerly my netlify/functions folder structure was

/functions 
  primes.js
  primeTest.js
  /generators
    genlastOneToo.js

where primes.js was the entry point and the other two files were dependencies. After looking at netlify build --help output, I changed it to:

/funcitons
   /primes
      primes.js
      primeTest.js
      genLastOneToo.js

And now I am getting different result, though still broken:

As I said, this site works on a local host (netlify dev). Looking at the crash report, I wonder if this is because I’m using ES6-style import/export in my lambda function; does the netlify.toml file need to change? I only ask because the function documentation uses CommonJS-style, though I did find a Netlify-authored blog post that used ES6-style.

The relevant code is here:

import primeGeneratorLastOneToo from "./genLastOneToo.js"

//...
import primeGeneratorLastOneToo from "./genLastOneToo.js"
...

const generatePrimes = (z) => {
...
	const prime = primeGeneratorLastOneToo(Z)  //failing here
...
}

export const handler = async (event, context) => {
	const {z} = event.queryStringParameters
	const {prime, elapsedTime} = generatePrimes(z);

    return {
      statusCode: 200,
      body: JSON.stringify({ prime: prime.toString(), elapsedTime}),
    };
  };

I hope that’s enough information! Logs follow.

jlowery2663@penguin:~/JPrime$ netlify build --debug

❯ Initial build environment
context: production
cwd: /home/jlowery2663/JPrime
featureFlags:
mode: cli
siteId: 9646c6f1-51e2-4386-b488-64c549a1c735

❯ UI build settings
baseRelDir: true
build:
command: react-scripts build
publish: build
functionsDirectory: netlify/functions

❯ Resolved build environment
branch: lastone_server
buildDir: /home/jlowery2663/JPrime
configPath: /home/jlowery2663/JPrime/netlify.toml
context: production
env:

  • DEPLOY_ID
  • BUILD_ID
  • REPOSITORY_URL
  • NETLIFY_LOCAL
  • HEAD
  • COMMIT_REF
  • CACHED_COMMIT_REF
  • PULL_REQUEST
  • LANG
  • LANGUAGE
  • LC_ALL
  • GATSBY_TELEMETRY_DISABLED
  • NEXT_TELEMETRY_DISABLED

    ❯ Resolved config
    build:
    command: react-scripts build
    commandOrigin: config
    publish: /home/jlowery2663/JPrime/build
    publishOrigin: config
    functionsDirectory: /home/jlowery2663/JPrime/netlify/functions

    ────────────────────────────────────────────────────────────────
    Netlify Build
    ────────────────────────────────────────────────────────────────

    ❯ Version
    @netlify/build 27.18.4

    ❯ Flags
    context: production
    debug: true
    dry: false
    featureFlags:
    • edge_functions_produce_eszip
      mode: cli
      offline: false
      siteId: 9646c6f1-51e2-4386-b488-64c549a1c735

      ❯ Current directory
      /home/jlowery2663/JPrime

      ❯ Config file
      /home/jlowery2663/JPrime/netlify.toml

      ❯ Resolved config
      build:
      command: react-scripts build
      commandOrigin: config
      publish: react-scripts build
      publishOrigin: config
      functionsDirectory: /home/jlowery2663/JPrime/netlify/functions

      ❯ Context
      production

      ────────────────────────────────────────────────────────────────
  1. build.command from netlify.toml
    ────────────────────────────────────────────────────────────────

    $ react-scripts build
    Creating an optimized production build…
    Compiled with warnings.

./src/Buttons.js
Line 21:20: Function declared in a loop contains unsafe references to variable(s) ‘resultCount’ no-loop-func

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.

File sizes after gzip:

42 KB build/static/js/2.d70c5ff3.chunk.js
1.85 KB build/static/js/main.41f9ec62.chunk.js
771 B build/static/js/runtime-main.bc640924.js
627 B build/static/css/main.e61ede8d.chunk.css

The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.

The build folder is ready to be deployed.
You may serve it with a static server:

yarn global add serve
serve -s build

Find out more about deployment here:

bit.ly/CRA-deploy


(build.command completed in 6.2s)

────────────────────────────────────────────────────────────────
2. Functions bundling
────────────────────────────────────────────────────────────────

Packaging Functions from netlify/functions directory:

  • primes/primes.js


    (Functions bundling completed in 206ms)

    ────────────────────────────────────────────────────────────────
    Netlify Build Complete
    ────────────────────────────────────────────────────────────────

jlowery2663@penguin:~/JPrime$ netlify deploy --debug --skip-functions-cache

❯ Initial build environment
cwd: /home/jlowery2663/JPrime
featureFlags:
mode: cli
siteId: 9646c6f1-51e2-4386-b488-64c549a1c735

❯ UI build settings
baseRelDir: true
build:
command: react-scripts build
publish: build
functionsDirectory: netlify/functions

❯ Resolved build environment
branch: lastone_server
buildDir: /home/jlowery2663/JPrime
configPath: /home/jlowery2663/JPrime/netlify.toml
context: production
env:

  • DEPLOY_ID
  • BUILD_ID
  • REPOSITORY_URL
  • NETLIFY_LOCAL
  • HEAD
  • COMMIT_REF
  • CACHED_COMMIT_REF
  • PULL_REQUEST
  • LANG
  • LANGUAGE
  • LC_ALL
  • GATSBY_TELEMETRY_DISABLED
  • NEXT_TELEMETRY_DISABLED

    ❯ Resolved config
    build:
    command: react-scripts build
    commandOrigin: config
    publish: /home/jlowery2663/JPrime/build
    publishOrigin: config
    functionsDirectory: /home/jlowery2663/JPrime/netlify/functions
    Deploy path: /home/jlowery2663/JPrime/build
    Functions path: /home/jlowery2663/JPrime/netlify/functions
    Configuration path: /home/jlowery2663/JPrime/netlify.toml
    Deploying to draft URL…
    :heavy_check_mark: Ignoring functions cache (use without --skip-functions-cache to change)
    :heavy_check_mark: Finished hashing 19 files and 1 functions
    :heavy_check_mark: CDN requesting 0 files and 0 functions
    :heavy_check_mark: Finished uploading 0 assets
    :heavy_check_mark: Deploy is live!

Logs: Netlify App
Website Draft URL: https://632e15b5fbe18d58948fa7e8--jprime.netlify.app

If everything looks good on your draft URL, deploy it to your main site URL with the --prod flag.
netlify deploy --prod

I changed the netlify.toml file from

[build]
  command = "react-scripts build"
  functions = "netlify/functions"
  publish = "build"

to

[build]
  command = "react-scripts build"
  # functions = "netlify/functions"
  publish = "build"

[functions]
  directory = "netlify/functions"
  node_bundler = "esbuild"

And now my deploys seem to work.

Hi @JeffML,

Thanks for reaching out and letting us know you were able to resolve the issue and providing the solution.

I hope you have a great day!