How to install the dependencies in the Editor runtime?

Dependencies were not successfully installed due to error:

Command failed: npm install <package> zsh:1: command not found: npm

For any failed npm installs above, run each listed install command manually from the root of this Editor workspace.

I tried to use exec to do npm install <package> it failed with the above issue. I dived into the Editor source code and found it has a EditorProcess to run the similar thing. However, I have to have editor object to use it.
I also found there was a package called fix-path which might be a potential solution to solve the PATH issue but in the Editor, it threw the following issue when I use the library.

/Applications/BabylonJS Editor.app/Contents/Resources/app.asar/build/src/renderer/editor/editor.js:1421 Error 
[ERR_REQUIRE_ESM]: Must use import to load ES Module: <path>
require() of ES modules is not supported.
require() of <path/index.js> from <path> is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.

Does anyone have the clues about solving these problems? Thank you.

It looks like you don’t have npm installed? Downloading and installing Node.js and npm | npm Docs

1 Like

Hi @ZzMarmot !

The editor is running thanks to electron which is based on some specific Node.JS versions. Here I think the Node.JS version used doesn’t support ESM modules where fix-path exports only as ESM modules.

I’m trying to solve the issue in the Editor and I’ll come with a fix :slight_smile:

@slin Unfortunately, when running the Editor from the Finder in macOS, not the entire env variables are available :frowning: Same on Linux

1 Like

Hey @julien-moreau,

I found a walkaround by using the fix-path version 3.0 which was supporting both ESM and CJS. You can take a look at this way on your end.

Also, what do you think about pure ESM decision?

Hi @slin ,
Thank you for the reply. The issue I hit was to run the npm install during the runtime in the Editor which like Julien said, it is not the same env as the local OS.

Hey @julien-moreau

I think a potential solution is to implement something similar as fix-path inside Editor to do the auto fix when launching.