- Do you want to request a _feature_ or report a _bug_?
Feature.
- What is the current behavior?
Unable to get the ES syntax working with Netlify Functions when deployed using Netlify Dev. Netlify will either complain about unsupported import statement, or when I change my functions to use the .mjs extension and add type: "module" to package.json, it will say the function cannot be found.
- If the current behavior is a bug, please provide the steps to reproduce.
N/A
- What is the expected behavior?
I should be able to use the same ES syntax in both client code and serverless functions to increase code reusability.
- Local Environment Information
Paste the results of netlify status --verbose here
System:
OS: macOS 10.15.3
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Binaries:
Node: 12.15.0 - ~/.nvm/versions/node/v12.15.0/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
npm: 6.13.4 - ~/.nvm/versions/node/v12.15.0/bin/npm
Browsers:
Chrome: 79.0.3945.130
Firefox: 69.0.1
Safari: 13.0.5
Hey @mrlubos I believe you cannot use import statements within Netlify functions without compile them with webpack! I learned however, you can do that using netlify-lambda! I am writing a blog post about this very thing but short synopsis:
netlify build <folder full of lambdas you want to compile>netlify.toml declare where your functions will be built and served from such asSo for instance my netlify.toml looks something like:
[build]
command = "npm run build" # This commands maps to building both my gatsby blog and my functions
functions = "functions-build" # where my functions will be located and I also link this on Netlify
The reason I figured this out was through this documentation here on When to use Netlify Dev, netlify-lambda, or both
Hi @maxcell, you're right! That's why I am requesting this as a new feature, one of my requirements is to use Netlify Dev as opposed to Netlify Lambda.
My bad about that one 馃槄, I'm not reading enough!
Thanks for looking into this issue! Hopefully somebody from Netlify will respond to it soon 馃ぇ