Error: Cannot find module 'env'
Require stack:
In the file ./pkg/hdbconnect_wasm_bg.js there is arequire("env"), but it is not in package.json
const path = require('path').join(__dirname, 'hdbconnect_wasm_bg.wasm');
const bytes = require('fs').readFileSync(path);
let imports = {};
imports['./hdbconnect_wasm.js'] = require('./hdbconnect_wasm.js');
imports['env'] = require('env');
const wasmModule = new WebAssembly.Module(bytes);
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
module.exports = wasmInstance.exports;
I tried a npm install env with no success.
git clone https://github.com/PSeitz/hdbconnect-wasm
wasm-pack build --target nodejs
ts-node test.ts
Include the relevant details of your environment.
wasm-pack version: tested with master and 0.8.1
rustc version: rustc 1.40.0-nightly (1423bec54 2019-11-05)
@ashleygwilliams Passing through and dropping a possible clue
env is added in
https://github.com/rustwasm/wasm-bindgen/blame/master/crates/threads-xform/src/lib.rs#L236
printed in
https://github.com/rustwasm/wasm-bindgen/blame/master/crates/cli-support/src/lib.rs#L726
require('env') will actually refer to this 8 years old module https://www.npmjs.com/package/env which I believe is not the intention
Should env be process.env?
If so JsGenerated.generate_node_wasm_import should need a more flexible imports definition, where other modules should be able to imports.add("process.env") instead of imports.add("env")
I am running into the same issue. Cannot run my binary on node because of require('env').
Don't know if it helps, but happens only on release. (with target web, so I should be able to run it on the browser as generated - no npm install)
@cedeber Yea, this is related to the nodejs target. When compiling to web everything works as expected.
I use the web target, and it's not working as you can see here: https://github.com/cedeber/fluss
Looks like the culpable is, or one of the optimizations in Cargo.toml (I used lto and opt-level), or wasm-opt I ran after wasm-pack. I didn't check which one exactly yet.
Hm interesting. It should not be caused by the opt-level nor the lto, cause I am also compiling for web and for the release profile I use
[profile.release]
lto = true
opt-level = "z"
I see here you are simply calling init, shouldn't you pass in a string so that the wasm is internally fetched via instantiateStreaming? At least that's what I am doing.
I have
lto = true
opt-level = "s"
so s instead of z for opt-level
I tried:
opt-level="s" alone: works โ
lto = true alone: fails โIf I'm using rustc 1.44.1 I have to remove lto = true to produce a working wasm. With rustc 1.45.0-beta.3 I can leave lto = true and I get a wasm without this error.
Not sure why but I am using nightly and lto works perfectly fine for me.
This problem went away for me by updating to Rust 1.46
@jakearchibald Do you know why it's fixed? Cause it still require's env and that package does not exist, cause to me this still seems to be an issue with the glue code generated by wasm-bindgen for the node target.
No idea, sorry ๐ข
Any new insights to this? Running into the same issue..
Same here! Also, do we know what exactly within Rust code triggers whether require('env') gets added to the Javascript output?
What're the odds of this being fixed in a timely fashion? My options are this being fixed this week or rewriting in JS...
I personally think this is a bug with wasm-bindgen that generates the require('env') in the binding.
Perhaps specific versions fo wasm-bindgen don't have this issue and could be used as a stop gap measure?
I have the same issue. I am using rust 1.46. It just appeared and wasn't there before.
Most helpful comment
Any new insights to this? Running into the same issue..