Is it possible to use ES6/import with JavaScript (...
# general
p
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
can you share your full code? i believe this should work
p
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
I didn't, can you open an issue please?
p
I'd be happy to, is https://github.com/pulumi/pulumi/issues the right place?
b
yup!