Can't compile wing using wing
I tried this
Tried running a wing app that compiles wing code
wing test -t sim test.w
test.w:
bring cloud;
resource Foo {
init(){}
extern "./external_js.js" static inflight wing_compile(code: str): str;
inflight compile(code: str): str {
return Foo.wing_compile(code);
}
}
let f = new Foo();
new cloud.Function(inflight () => {
log(f.compile("log(\"this will be logged as well\");"));
}) as "test:call";
external_js:
const { compile, Target} = require('winglang/dist/commands/compile');
const { writeFile, readFile } = require('fs/promises');
const { join } = require('path');
exports.wing_compile = async function(code) {
const wingFile = "/tmp/test.w";
await writeFile(wingFile, code, "utf-8");
const outDir = await compile(wingFile, { target: Target.TF_AWS });
const tfJson = await readFile(join(outDir, 'main.tf.json'), 'utf-8');
return tfJson;
};
I expected this:
the test to run and to see the output this will be logged as well
Instead, this happened
got en error:
../node_modules/.bin/wing test -t sim ../test.w
✔ Compiling to sim...
fail ┌ test.wsim » root/env0/test:call
│ TypeError: Cannot read properties of undefined (reading 'fd')
│ at Function.useColors (/private/tmp/a2/node_modules/winglang/node_modules/debug/src/node.js:158:29)
│ at createDebug (/private/tmp/a2/node_modules/winglang/node_modules/debug/src/common.js:117:33)
│ at /private/tmp/a2/node_modules/winglang/node_modules/wasi-js/dist/wasi.js:16:33
│ at VM2 Wrapper.apply (/private/tmp/a2/node_modules/@winglang/sdk/node_modules/vm2/lib/bridge.js:485:11)
│ at NodeVM.run (/private/tmp/a2/node_modules/@winglang/sdk/node_modules/vm2/lib/nodevm.js:426:23)
│ at DefaultResolver.loadJS (/private/tmp/a2/node_modules/@winglang/sdk/node_modules/vm2/lib/resolver.js:202:7)
│ at loadJS (/private/tmp/a2/node_modules/@winglang/sdk/node_modules/vm2/lib/nodevm.js:249:46)
│ at VM2 Wrapper.apply (/private/tmp/a2/node_modules/@winglang/sdk/node_modules/vm2/lib/bridge.js:485:11)
│ at Module._extensions.<computed> (/private/tmp/a2/node_modules/@winglang/sdk/node_modules/vm2/lib/setup-node-sandbox.js:144:48)
└ at requireImpl (/private/tmp/a2/node_modules/@winglang/sdk/node_modules/vm2/lib/setup-node-sandbox.js:117:3)
Is there a workaround?
No response
Component
SDK
Wing Version
No response
Wing Console Version
No response
Node.js Version
No response
Platform(s)
No response
Anything else?
the error seems to point that process.stderr is missing from the global object. But even when fixing that there are also some mismatches between types inside the vm and outside of it.
Community Notes
- Please vote by adding a 👍 reaction to the issue to help us prioritize.
- If you are interested to work on this issue, please leave a comment.
Hi,
This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!
Hi,
This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!
Hi,
This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!
I modernized the code and no errors are now thrown, but the log message is still not printed, so I'll keep the issue. main.w:
bring cloud;
class Foo {
new(){}
extern "./comp_ext.js" static inflight wingCompile(code: str): str;
pub inflight compile(code: str): str {
return Foo.wingCompile(code);
}
}
let f = new Foo();
new cloud.Function(inflight () => {
log(f.compile("log(\"this will be logged as well\");"));
}) as "test:call";
comp_ext.js:
const { compile, Target } = require("winglang/dist/commands/compile");
const { writeFile, readFile } = require("fs/promises");
const { join } = require("path");
exports.wingCompile = async function (code) {
const wingFile = "/tmp/test.w";
await writeFile(wingFile, code, "utf-8");
const outDir = await compile(wingFile, { target: Target.TF_AWS });
const tfJson = await readFile(join(outDir, "main.tf.json"), "utf-8");
return tfJson;
};
Hi,
This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!