https://pulumi.com logo
p

plain-keyboard-29627

10/26/2021, 4:53 PM
Is it possible to use ES6/import with JavaScript (not TypeScript)? If I create a skeleton using
pulumi new javascript
and attempt to change
const pulumi = require("@pulumi/pulumi");
into
import pulumi from "@pulumi/pulumi";
, if I run/preview, I always get the following error:
Copy code
error: Running program 'c:\code\xyz\infra' failed with an unhandled exception:
Error [ERR_REQUIRE_ESM]: require() of ES Module c:\code\xyz\infra\index.js from c:\code\xyz\infra\node_modules\@pulumi\pulumi\cmd\run\run.js not supported.
Instead change the require of index.js in c:\code\xyz\infra\node_modules\@pulumi\pulumi\cmd\run\run.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (c:\code\xyz\infra\node_modules\@pulumi\pulumi\cmd\run\run.js:219:31)
I tried setting up the module either with
"type": "module"
in my package.json or by renaming index.js to index.mjs and using
"main": "index.mjs"
in package.json. Same error both ways.
b

billowy-army-68599

10/26/2021, 4:58 PM
can you share your full code? i believe this should work
p

plain-keyboard-29627

10/26/2021, 5:17 PM
I think https://github.com/leviwolfe/import-pulumi should repro what I see.
Hi @billowy-army-68599 any chance you looked at that repo?
I tried to limit the breaking change to a single commit to demonstrate when it stops working. Would love to know if I'm doing something wrong. Thanks.
b

billowy-army-68599

11/04/2021, 7:08 PM
I didn't, can you open an issue please?
p

plain-keyboard-29627

11/04/2021, 7:13 PM
I'd be happy to, is https://github.com/pulumi/pulumi/issues the right place?
b

billowy-army-68599

11/04/2021, 7:20 PM
yup!
18 Views