emscripten-core / emsdk

Emscripten SDK
http://emscripten.org
Other
3.02k stars 688 forks source link

Inconsistent availability of node and npm binaries after sourcing emsdk_env.sh multiple times #1240

Closed shakhvit closed 1 year ago

shakhvit commented 1 year ago

Description:

When I source the environment setup file emsdk_env.sh for emsdk (commit c2260b4f28f53b411032de0955a6fe6b6bcf3edd -- current main), node and npm binaries are correctly added to my path the first time. However, when I source emsdk_env.sh again, node and npm are no longer accessible. Sourcing a third time brings them back, and this pattern continues with each subsequent sourcing.

Steps to reproduce:

  1. Clone the most recent version of emsdk (commit c2260b4f28f53b411032de0955a6fe6b6bcf3edd).
  2. Run the commands:
    ./emsdk install 3.1.3
    ./emsdk activate 3.1.3
  3. Source the environment with source ./emsdk_env.sh.
  4. Check that node and npm are available by running node -v and npm -v.
  5. Source the environment again with source ./emsdk_env.sh.
  6. Check node and npm availability again. They are not found.
  7. Source the environment again and check node and npm. They are available again.
  8. Continue this cycle of sourcing and checking. You will see that the availability of node and npm alternates with each sourcing.

Environment:

I hope this issue can be addressed. Thank you for your time and help.

sbc100 commented 1 year ago

Thanks for the report.. I actually noticed this issue the other day myself.

Its actually good to know that you noticed this... since I wasn't sure if folks out there were using out embedded version of node outside of the emcc tool. Can I ask what you are using it for?

BTW, one temporary solution is to use the $EMSDK_NODE environment variable which we set to point to this copy of node.

shakhvit commented 1 year ago

@sbc100, thank you for your response. I've already developed a temporary workaround for this issue. The solution involves creating a wrapper script that guarantees emsdk_env.sh is only sourced a single time.

Our project requires both emcc (for compiling C++ code into WASM) and Node.js (for operating certain backend network components). Given that emcc's toolkit already includes Node.js, it makes sense for us to utilize this bundled Node.js. It saves us from having to manage a separate Node.js installation. :)

sbc100 commented 1 year ago

I see. Interesting to know that some folks are taking advantage of our bundled version of node. My understanding was that most folks using node in production would actually want something a lot more recent (and more under their own control), but I stand corrected.

Another temporary option would be to install your own separate version of node. Even with the current bug emsdk_env should never remove that version from you PATH.