https://pulumi.com logo
#general
Title
# general
a

acoustic-arm-10406

08/19/2021, 6:29 PM
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

little-cartoon-10569

08/19/2021, 10:08 PM
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

acoustic-arm-10406

08/20/2021, 4:25 PM
Yeah TS -> JS just moves it to commonJS ... We opted not to use TS so I'll just write it in commonJS. Thanks.
16 Views