liweijian
liweijian
CDCloudflare Developers
Created by liweijian on 6/30/2023 in #general-help
How to make `wrangler dev` run in background?
I wanna to create a wasm demo for internal usage: https://developers.cloudflare.com/workers/platform/webassembly/javascript/ I can run by wrangler dev in terminal, but need to keep the terminal. Is there any way to make it run in ubuntu's background?
2 replies
CDCloudflare Developers
Created by liweijian on 6/30/2023 in #general-help
got `errno: -32` when `wrangler dev`
I'm using $ wrangler init to init a project, change the code of worker.ts, and run with wrangler dev, OS: Ubuntu 20.04 Node.js v18.16.0 Got error:
$ wrangler dev
...
[mf:wrn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2023-05-18",
but you've requested "2023-06-30". Falling back to "2023-05-18"...
...
│ [b] open a browser, [d] open Devtools, [l] turn off local mode, [c] clear console, [x] to exit │
...
/home/ubuntu/.nvm/versions/node/v18.16.0/lib/node_modules/wrangler/wrangler-dist/cli.js:30632
throw a;
^

Error: write EPIPE
at afterWriteDispatched (node:internal/stream_base_commons:160:15)
at writeGeneric (node:internal/stream_base_commons:151:3)
at Socket._writeGeneric (node:net:930:11)
at Socket._write (node:net:942:8)
at writeOrBuffer (node:internal/streams/writable:392:12)
at _write (node:internal/streams/writable:333:10)
at Writable.write (node:internal/streams/writable:337:10)
at Runtime.updateConfig (/home/ubuntu/.nvm/versions/node/v18.16.0/lib/node_modules/wrangler/node_modules/miniflare/dist/src/index.js:5125:26)
at async #assembleAndUpdateConfig (/home/ubuntu/.nvm/versions/node/v18.16.0/lib/node_modules/wrangler/node_modules/miniflare/dist/src/index.js:9140:23)
at async #init (/home/ubuntu/.nvm/versions/node/v18.16.0/lib/node_modules/wrangler/node_modules/miniflare/dist/src/index.js:8902:5)
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -32,
code: 'EPIPE',
syscall: 'write'
}

Node.js v18.16.0
$ wrangler dev
...
[mf:wrn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2023-05-18",
but you've requested "2023-06-30". Falling back to "2023-05-18"...
...
│ [b] open a browser, [d] open Devtools, [l] turn off local mode, [c] clear console, [x] to exit │
...
/home/ubuntu/.nvm/versions/node/v18.16.0/lib/node_modules/wrangler/wrangler-dist/cli.js:30632
throw a;
^

Error: write EPIPE
at afterWriteDispatched (node:internal/stream_base_commons:160:15)
at writeGeneric (node:internal/stream_base_commons:151:3)
at Socket._writeGeneric (node:net:930:11)
at Socket._write (node:net:942:8)
at writeOrBuffer (node:internal/streams/writable:392:12)
at _write (node:internal/streams/writable:333:10)
at Writable.write (node:internal/streams/writable:337:10)
at Runtime.updateConfig (/home/ubuntu/.nvm/versions/node/v18.16.0/lib/node_modules/wrangler/node_modules/miniflare/dist/src/index.js:5125:26)
at async #assembleAndUpdateConfig (/home/ubuntu/.nvm/versions/node/v18.16.0/lib/node_modules/wrangler/node_modules/miniflare/dist/src/index.js:9140:23)
at async #init (/home/ubuntu/.nvm/versions/node/v18.16.0/lib/node_modules/wrangler/node_modules/miniflare/dist/src/index.js:8902:5)
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -32,
code: 'EPIPE',
syscall: 'write'
}

Node.js v18.16.0
2 replies
CDCloudflare Developers
Created by liweijian on 5/24/2023 in #workers-help
How to import javascript function from Wasm?
I'm trying to import a javascript function from Wasm. For the worker.ts, I defined a function consoleLog:
import mod from '../build/out.wasm';

const importObject = {
imports: {
consoleLog: (arg: number) => {
console.log(`Hello from JavaScript: ${arg}`);
},
},
};

const instance = await WebAssembly.instantiate(mod, importObject);

export default {
async fetch() {
const retval = instance.exports.add100(2, 5);
return new Response(`Success: ${retval}`);
},
};
import mod from '../build/out.wasm';

const importObject = {
imports: {
consoleLog: (arg: number) => {
console.log(`Hello from JavaScript: ${arg}`);
},
},
};

const instance = await WebAssembly.instantiate(mod, importObject);

export default {
async fetch() {
const retval = instance.exports.add100(2, 5);
return new Response(`Success: ${retval}`);
},
};
And I'm using AssemblyScript for the Wasm side:
declare function consoleLog(arg0: i32): void;

export function add100(a: i32, b: i32): i32 {
// consoleLog(100);
return a + b + 100;
}
declare function consoleLog(arg0: i32): void;

export function add100(a: i32, b: i32): i32 {
// consoleLog(100);
return a + b + 100;
}
Since I commented the //consoleLog(100); out, it works well after compile:
asc assembly/index.ts --outFile build/out.wasm --optimize
asc assembly/index.ts --outFile build/out.wasm --optimize
However, when I un-commented it as:
declare function consoleLog(arg0: i32): void;

export function add100(a: i32, b: i32): i32 {
consoleLog(100);
return a + b + 100;
}
declare function consoleLog(arg0: i32): void;

export function add100(a: i32, b: i32): i32 {
consoleLog(100);
return a + b + 100;
}
I got an error after asc:
service core:user:wasm102: Uncaught Error: No such module "bea1e1adde3b4c3c5cbc0842c823a3c93a930163-out.wasm".
imported from "worker.js"
[ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.
service core:user:wasm102: Uncaught Error: No such module "bea1e1adde3b4c3c5cbc0842c823a3c93a930163-out.wasm".
imported from "worker.js"
[ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.
Just wondering what's the appropriate way to import javascript function from Wasm?
2 replies