Cannot use Rust because the NodeJS `util` module is not available
See original GitHub issueI am trying to use Rust to program my screeps, and I am using wasm-bindgen for this (which is the standard way of combining Rust and JS).
However, this requires the TextDecoder
API for encoding strings, which is available in the "util"
module in NodeJS. But the "util"
module is not available in screeps (require("util")
gives an error).
In addition, TextDecoder
and global.TextDecoder
are not available either. Therefore I cannot use Rust with screeps.
The solution is for screeps to add in support for the "util"
module in NodeJS, or alternatively upgrade to NodeJS version 11 (which has support for TextDecoder
on the global object).
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Top Results From Across the Web
How to import util module in Node.js? - Stack Overflow
I confirmed this method is available on command line: D:\>node Welcome to Node.js v12. · Here is my code: class App extends Component...
Read more >How to Use Rust with Node.js When Performance Matters
Rust promises speed, safety, and concurrency. Let's see how can you use it with Node.js.
Read more >Rust and Node.js: A match made in heaven - LogRocket Blog
Worker threads are great, but they're not available in all supported versions of Node. Fortunately, you can use Rust to build a native ......
Read more >Web Extensions - Visual Studio Code
Web extensions still have access to the full VS Code API, but no longer to ... work because there is a shim for...
Read more >How to solve "Error: Cannot find module '*.js'" with Node.js
then you are most likely trying to run the wrong file. It is possible you are missing a dependency that is needed from...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I filed a PR upstream to get this supported: https://screeps.com/forum/topic/3067/allow-access-to-node-s-textdecoder
Interestingly,
TextDecoder
already works in the simulator (as the object just exists at the global scope). I was able to get a Rust “Hello World” program working in the tutorial.I think the best way forward is to just give screeps add the ability to call
requires("util")
in their Node installation. This API has been supported since Node 8, so this should just be a config change (as screeps mandates Node 10). The current Rust API bindings for screeps use an old version ofstdweb
that avoids TextDecoder IIRC. The two main issues are thatstdweb
is no longer maintained, and the replacementwasm-bindgen
(which is offically supported by the Rust project) uses the TestEncoder/Decoder APIs to speed up calling across the js/wasm boundary.I’m not super familiar with how screeps is maintained/updated, but I’d be happy to submit a PR if someone could give me some pointers about how to change things.