I'm feeling daft... can anyone explain to me how t...
# general
a
I'm feeling daft... can anyone explain to me how to follow these instructions and use
Copy code
import * as awsx from "@pulumi/awsx";
https://www.pulumi.com/docs/guides/crosswalk/aws/api-gateway/#defining-a-lambda-function-event-handler-route When I do
pulumi up
It's saying I have to use
require
because of a node_module from pulumi is using require. I would like to use import instead of refactoring all my code to use require Error:
Copy code
require() of /index.js from /node_modules/@pulumi/pulumi/cmd/run/run.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
    Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /package.json.
Hmm... turns out all the examples I'm seeing (including this docs page) are in typescript, which seems to handle the import. So if you choose javascript you have to use require.
l
Lambdas cannot use
"type":"module"
even if your runtime is node14. Don't know why. So if you want to create a pure JS package for your lambdas, you either need to use commonJS, or transpile down to that. I don't know how to transpile JS->JS; the TS->JS transpilation done with Pulumi's default config has always worked for me.
a
Yeah TS -> JS just moves it to commonJS ... We opted not to use TS so I'll just write it in commonJS. Thanks.