Can I use NPM packages in lambda script?

Hi,

I finally got the Cloud API running and can now deploy lambda scripts from my local machine. Obviously lambdas make only sense (e.g. connecting to another server to fetch an auth token) if I can use NPM packages like node-fetch for example. I was following your blogs and the source of the deprecated slash-graphql and you were using webpack to bundle all of the sources together and push it to the cloud. Unfortunately I have a problem with target: webworker in the webpack config. I get loads of errors since I guess some NPM packages are not supported.

Does anyone have the same problem? How did you solve this? Can we use NPM packages directly in lambda scripts?

Thanks!

Webpack would be the only way I know of to do this (basically concatenating all the scripts together). Note they do have some available libraries built in, including fetch:

   // From fetch
    fetch,
    Request,
    Response,
    Headers,

    // URL Standards
    URL,
    URLSearchParams,

    // bas64
    atob,
    btoa,

    // Crypto
    crypto: new Crypto(),
    TextDecoder,
    TextEncoder,

    // Debugging
    console,

    // Async
    setTimeout,
    setInterval,
    clearTimeout,
    clearInterval,
...

As far as issues with webpack, I have not had any - though as you say it may be package dependent.

1 Like