Is it possible to use ES6/import with JavaScript (...
# general
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");
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.
can you share your full code? i believe this should work
I think 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.
I didn't, can you open an issue please?
I'd be happy to, is the right place?