Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle Theia backend #12391

Closed
msujew opened this issue Apr 11, 2023 · 7 comments · Fixed by #12412
Closed

Bundle Theia backend #12391

msujew opened this issue Apr 11, 2023 · 7 comments · Fixed by #12412
Assignees
Labels
theia-cli issues related to the theia-cli

Comments

@msujew
Copy link
Member

msujew commented Apr 11, 2023

Feature Description:

Even though node.js is able to run the Theia backend as it is (fragmented across node_modules) perfectly fine, it would be worth looking into bundling the backend. This has a few benefits for devs/users:

  • Faster Startup. Less file system accesses and minification lead to shorter cold startup times.
  • Smaller application sizes. This is particularly relevant for the Electron build which users have to download and install to disk.
  • Simplifies moving the application from one directory/system to another. Relevant for Support SSH Remote Development #12390
@msujew msujew added the theia-cli issues related to the theia-cli label Apr 11, 2023
@msujew msujew self-assigned this Apr 11, 2023
@kittaakos
Copy link
Contributor

Related: #4541

@sdirix
Copy link
Member

sdirix commented Apr 13, 2023

For anyone interested: There is a WIP PR by @paul-marechal for Theia Blueprint which includes bundling the backend with Webpack.

@msujew
Copy link
Member Author

msujew commented May 31, 2023

Just a few remarks on the implemented changes from #12412:

  • Server cold startup time down from ~4 seconds to ~1.5 seconds.
  • Full application size down from ~300mb to ~130mb.

@jfaltermeier
Copy link
Contributor

jfaltermeier commented Jul 4, 2023

Hi, I was trying to integrate these changes in Theia Blueprint and struggled.
So I thought I will give it a try with the Theia Electron Example first.

So basically what I did is to replace
"bundle": "yarn rebuild && theia build --mode development" with "bundle": "yarn rebuild && theia build --mode production" and updated start like this "start": "node ./lib/backend/electron-main.js", in theia/examples/electron/package.json

On ubuntu running yarn electron build fails with

ERROR in ../../node_modules/@vscode/proxy-agent/out/index.js 380:70-105
Module not found: Error: Can't resolve '@vscode/windows-ca-certs/build/Release/crypt32.node' in '/home/johannes/Git/theia/node_modules/@vscode/proxy-agent/out'
resolve '@vscode/windows-ca-certs/build/Release/crypt32.node' in '/home/johannes/Git/theia/node_modules/@vscode/proxy-agent/out'
  Parsed request is a module
  using description file: /home/johannes/Git/theia/node_modules/@vscode/proxy-agent/package.json (relative path: ./out)
    resolve as module
      /home/johannes/Git/theia/node_modules/@vscode/proxy-agent/out/node_modules doesn't exist or is not a directory
      looking for modules in /home/johannes/Git/theia/node_modules/@vscode/proxy-agent/node_modules
        /home/johannes/Git/theia/node_modules/@vscode/proxy-agent/node_modules/@vscode/windows-ca-certs doesn't exist
      /home/johannes/Git/theia/node_modules/@vscode/node_modules doesn't exist or is not a directory
      /home/johannes/Git/theia/node_modules/node_modules doesn't exist or is not a directory
      looking for modules in /home/johannes/Git/theia/node_modules
        /home/johannes/Git/theia/node_modules/@vscode/windows-ca-certs doesn't exist
      looking for modules in /home/johannes/Git/node_modules
        /home/johannes/Git/node_modules/@vscode/windows-ca-certs doesn't exist
      /home/johannes/node_modules doesn't exist or is not a directory
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
 @ ../../packages/plugin-ext/lib/hosted/node/plugin-host-proxy.js 22:22-52
 @ ../../packages/plugin-ext/lib/hosted/node/plugin-host-rpc.js 35:28-58
 @ ../../packages/plugin-ext/lib/hosted/node/plugin-host.js 21:26-54

webpack 5.76.2 compiled with 1 error and 136 warnings in 64656 ms

Error: webpack exited with an unexpected code: 1.
    at ChildProcess.<anonymous> (/home/johannes/Git/theia/dev-packages/application-manager/lib/application-process.js:66:28)
    at ChildProcess.emit (node:events:520:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

On windows running yarn electron build works. When running yarn electron start (without deleting any node_modules yet) I get this error:

TypeError: Cannot set properties of undefined (setting 'allowRendererProcessReuse')
    at Object.2951 (C:\Users\user\git\theia\examples\electron\lib\backend\electron-main.js:1:3177)
    at o (C:\Users\user\git\theia\examples\electron\lib\backend\electron-main.js:1:42522)
    at C:\Users\user\git\theia\examples\electron\lib\backend\electron-main.js:1:42650
    at Function.o.O (C:\Users\user\git\theia\examples\electron\lib\backend\electron-main.js:1:42901)
    at o.x (C:\Users\user\git\theia\examples\electron\lib\backend\electron-main.js:1:42671)
    at Function.o.x (C:\Users\user\git\theia\examples\electron\lib\backend\electron-main.js:1:43866)
    at C:\Users\user\git\theia\examples\electron\lib\backend\electron-main.js:1:43873
    at Object.<anonymous> (C:\Users\user\git\theia\examples\electron\lib\backend\electron-main.js:1:43878)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Am I doing something wrong or is there an issue with the current release?

@msujew
Copy link
Member Author

msujew commented Jul 4, 2023

@jfaltermeier Weird, I'll take a look at it over at eclipse-theia/theia-blueprint#275. We've already successfully integrated the feature in one of our projects (Electron+Browser, Windows+Ubuntu+Mac), so I'm fairly certain it works as expected.

@zhaomenghuan
Copy link
Contributor

@msujew Hello,do you have a configuration for not bundling the backend? After upgrading to the latest version, my application is not running properly.

@msujew
Copy link
Member Author

msujew commented Oct 11, 2023

@zhaomenghuan You can just remove the backendConfig from the webpack.config.js of your application. That will stop the backend bundling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theia-cli issues related to the theia-cli
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants