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

Generate webpack config for backend bundling #12412

Merged
merged 17 commits into from
Jun 15, 2023
Merged

Conversation

msujew
Copy link
Member

@msujew msujew commented Apr 13, 2023

What it does

Closes #12391

Generates in addition to the existing gen-webpack.config.js another gen-webpack.node.config.js. This configuration can be used to also bundle the applications backend. Note that this change completely optional, and devs can still opt for running a non-bundled backend.

In order to simplify copying & and modifying native executables, a new package is introduced @theia/native-webpack-plugin. It handles webpack bundling for special, hard to bundle native dependencies such as @vscode/ripgrep, drivelist, native-keymap and node-pty.

How to test

This change affects both the browser and electron version of Theia. Please perform all testing steps on both platforms:

Optional Bundling
  1. Build and bundle the application as normal. The application should behave as usual and exhibit no regressions. Some possible regressions might include:
    • Terminals not starting
    • Plugin host not working
    • Git extension not working
    • Search features not working
  2. Using --mode=production should produce a minified production build that also works as expected.
  3. Remove the backend bundling step from the webpack.config.js and clean the repo. Running theia build should result in a non-bundled backend that still starts/works as expected.
No dependencies on node_modules
  1. Build and bundle the application
  2. Delete the node_modules (except for the electron dependency).
  3. Modify the start scripts to something like this node ./lib/backend/main.js.
  4. Start the browser and electron app, and assert that they work as expected.
Debugging

Run all relevant debug configurations and confirm that debugging the application (especially the backend) works as expected.

Electron Application Bundling

Note: I haven't performed this step myself yet due to a lack of time. It might not work as expected yet.

  1. Bundle the electron app into an actual application
  2. Assert that everything works as expected.

Review checklist

Reminder for reviewers

@kittaakos
Copy link
Contributor

kittaakos commented Apr 28, 2023

I could not start the electron example app from VS Code using the Launch Electron Backend launch configuration.

I did:

% git rev-parse --short HEAD
1a9272f3ff
% yarn && yarn build && yarn browser rebuild && yarn electron rebuild

[...]

✔ Rebuild Complete
✨  Done in 23.21s.
Click to see what I got when I started Theia from Code:

/Users/a.kitta/dev/git/theia/node_modules/.bin/electron . --log-level=debug --hostname=localhost --no-cluster --app-project-path=/Users/a.kitta/dev/git/theia/examples/electron --remote-debugging-port=9222 --no-app-auto-install --plugins=local-dir:../../plugins
Debugger listening on ws://127.0.0.1:50735/3f8b92ea-a73d-454a-9b9f-03d41117ce38
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Debugger listening on ws://127.0.0.1:50739/a50e31e3-59fd-42b8-bc42-e85b14b0eebd
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/api.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/api.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/cancellation.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/cancellation.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/connection.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/connection.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/disposable.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/disposable.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/events.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/events.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/is.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/is.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/linkedMap.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/linkedMap.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messageBuffer.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messageBuffer.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messageReader.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messageReader.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messageWriter.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messageWriter.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messages.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messages.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/ral.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/ral.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/semaphore.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/semaphore.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/node/main.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/node/main.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/node/ril.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/node/ril.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/api.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/api.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/connection.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/connection.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/messages.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/messages.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.callHierarchy.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.callHierarchy.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.colorProvider.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.colorProvider.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.configuration.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.configuration.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.declaration.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.declaration.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.diagnostic.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.diagnostic.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.fileOperations.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.fileOperations.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.foldingRange.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.foldingRange.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.implementation.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.implementation.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.inlayHint.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.inlayHint.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.inlineValue.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.inlineValue.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.linkedEditingRange.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.linkedEditingRange.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.moniker.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.moniker.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.notebook.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.notebook.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.progress.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.progress.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.selectionRange.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.selectionRange.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.semanticTokens.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.semanticTokens.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.showDocument.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.showDocument.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.typeDefinition.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.typeDefinition.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.typeHierarchy.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.typeHierarchy.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.workspaceFolder.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.workspaceFolder.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/utils/is.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/utils/is.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/node/main.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/node/main.js.map'
Failed to start the electron application.
Error: Cannot find module '/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/main.js'
    at webpackEmptyContext (/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/electron-main.js:2088:10)
    at ElectronMainApplication.startBackend (/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/electron-main.js:1111:110)
    at ElectronMainApplication.start (/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/electron-main.js:872:33)
    at start (/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/electron-main.js:267:23)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'MODULE_NOT_FOUND'
}

DevTools listening on ws://127.0.0.1:9222/devtools/browser/0315b9ee-2678-4e73-96f6-b8e73ae57af6

@paul-marechal paul-marechal self-requested a review May 1, 2023 00:51
@msujew
Copy link
Member Author

msujew commented May 3, 2023

@kittaakos I've noticed that the webpack plugin doesn't work well when building multiple projects at the same time. I've adapted it a bit. It should work as expected now 👍

@kittaakos
Copy link
Contributor

I've noticed that the webpack plugin doesn't work well when building multiple projects at the same time. I've adapted it a bit. It should work as expected now 👍

Thank you for the ping and update, @msujew.

I tried it yesterday, right after you had updated the PR, but I had the same problem.

% git status
On branch msujew/bundle-backend
Your branch is up to date with 'upstream/msujew/bundle-backend'.

nothing to commit, working tree clean
% git rev-parse --short HEAD
e4999e6400

I have checked the files, and the generated modules were all there. I will give it another try with a fresh clone soon.

@msujew
Copy link
Member Author

msujew commented May 3, 2023

@kittaakos I've just identified the issue. It's supposed to go trough the "real" require mechanism in that case, but it tries to use the webpack_require instead. Let me quickly fix that.

Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I experimented with this PR using a non-trivial Theia-based application on Windows 11:

  • Backported the change to Theia 1.34.2
  • Consumed Theia as source in the Theia-based application

We have some manual file system operations in our extensions using __dirname. These were then failing, so I removed them for now. Maybe the webpack build could warn when such constructs are encountered.

Besides that problem and a small hiccup with the generated webpack file I got the Browser variant working. I was successfully able remove the node_modules directory and was still able to run the Theia backend 🎉

However I failed to get the Electron variant to run. For the build I had to add --max-old-space-size=4096 as the Webpack build now required more memory. But even with that out of the way and the build succeeding, Electron immediately crashed with a Javascript error in the main process: "Uncaught Exception: Error: No native build was found for platform=win32 arch=x64 runtime=electron abi=98 uv=1 libc=glibc node=16.5.0 electron=15.5.7 webpack=true loaded from: C:\theia-webpack\apps\electron\lib".

I tried to start the Electron variant with commands like node_modules/.bin/electron.cmd . --app-project-path=. and adapted the main path of the Electron app package to the lib/backend/electron-main.js file.

Do I have to do something different? I was able to start the regular Electron build this way.

@kittaakos
Copy link
Contributor

Hi, I have checked out this branch multiple times but still cannot start the electron example application from VS Code. What am I doing wrong? I check out the branch, run yarn && yarn build && yarn browser rebuild && yarn electron rebuild, and launch the Launch Electron Backend config.

click to see full debug console output

/Users/a.kitta/dev/git/theia/node_modules/.bin/electron . --log-level=debug --hostname=localhost --no-cluster --app-project-path=/Users/a.kitta/dev/git/theia/examples/electron --remote-debugging-port=9222 --no-app-auto-install --plugins=local-dir:../../plugins
Debugger listening on ws://127.0.0.1:63073/482cbb57-8b6c-473f-a0c4-d267c32b36bc
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Debugger listening on ws://127.0.0.1:63076/de8a43c1-87c6-423e-9800-4296624d8a8f
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/api.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/api.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/cancellation.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/cancellation.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/connection.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/connection.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/disposable.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/disposable.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/events.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/events.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/is.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/is.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/linkedMap.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/linkedMap.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messageBuffer.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messageBuffer.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messageReader.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messageReader.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messageWriter.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messageWriter.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messages.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/messages.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/ral.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/ral.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/semaphore.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/common/semaphore.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/node/main.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/node/main.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/node/ril.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-jsonrpc/lib/node/ril.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/api.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/api.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/connection.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/connection.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/messages.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/messages.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.callHierarchy.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.callHierarchy.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.colorProvider.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.colorProvider.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.configuration.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.configuration.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.declaration.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.declaration.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.diagnostic.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.diagnostic.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.fileOperations.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.fileOperations.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.foldingRange.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.foldingRange.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.implementation.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.implementation.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.inlayHint.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.inlayHint.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.inlineValue.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.inlineValue.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.linkedEditingRange.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.linkedEditingRange.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.moniker.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.moniker.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.notebook.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.notebook.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.progress.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.progress.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.selectionRange.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.selectionRange.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.semanticTokens.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.semanticTokens.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.showDocument.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.showDocument.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.typeDefinition.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.typeDefinition.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.typeHierarchy.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.typeHierarchy.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.workspaceFolder.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/protocol.workspaceFolder.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/utils/is.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/common/utils/is.js.map'
Could not read source map for file:///Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/node/main.js: ENOENT: no such file or directory, open '/Users/a.kitta/dev/git/theia/node_modules/vscode-languageserver-protocol/lib/node/main.js.map'
Failed to start the electron application.
Error: node-loader:
Error: Module did not self-register: '/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/native/drivelist.node'.
    at ../../node_modules/drivelist/build/Release/drivelist.node (/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/vendors-node_modules_drivelist_build_Release_drivelist_node-dev-packages_ovsx-client_node_mod-620318.js:33:9)
    at __webpack_require__ (/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/main.js:25690:42)
    at module.exports (/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/main.js:502:34)
    at ../../node_modules/drivelist/js/index.js (/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/vendors-node_modules_drivelist_build_Release_drivelist_node-dev-packages_ovsx-client_node_mod-620318.js:11784:27)
    at __webpack_require__ (/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/main.js:25690:42)
    at ../../packages/core/lib/node/env-variables/env-variables-server.js (/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/main.js:2189:19)
    at __webpack_require__ (/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/main.js:25690:42)
    at ../../packages/core/lib/node/env-variables/index.js (/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/main.js:2298:14)
    at __webpack_require__ (/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/main.js:25690:42)
    at ../../packages/core/lib/node/backend-application-module.js (/Users/a.kitta/dev/git/theia/examples/electron/lib/backend/main.js:1977:25)
[35442:0522/090114.647320:ERROR:socket_posix.cc(147)] bind() failed: Address already in use (48)
[35442:0522/090114.647752:ERROR:devtools_http_handler.cc(310)] Cannot start http server for devtools.
Debugger ending on ws://127.0.0.1:63073/482cbb57-8b6c-473f-a0c4-d267c32b36bc
For help, see: https://nodejs.org/en/docs/inspector
Debugger ending on ws://127.0.0.1:63076/de8a43c1-87c6-423e-9800-4296624d8a8f
For help, see: https://nodejs.org/en/docs/inspector
[35442:0522/090123.473090:ERROR:gpu_process_host.cc(953)] GPU process exited unexpectedly: exit_code=9

Thank you!

@msujew
Copy link
Member Author

msujew commented May 22, 2023

@kittaakos yarn electron rebuild needs to be performed before yarn build, as the native dependencies are already moved to their target destination when running yarn build. Running yarn electron rebuild afterwards has no effect.

I'm wondering right now how to improve on this. Any idea?

@kittaakos
Copy link
Contributor

@kittaakos yarn electron rebuild needs to be performed before yarn build,

This is working great now. I can debug the Theia backend too. That is a very nice feature. Thank you! I will take a deeper look this week.

Copy link
Member

@paul-marechal paul-marechal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good with only a few comments. I can run the app and debug from TS sources.

@msujew
Copy link
Member Author

msujew commented May 24, 2023

@paul-marechal Thanks, yeah that irked me quite a bit as well. I've moved all backend components into a backend directory parallel to lib. Also, to simplify the generated electron file, I've moved electron-main from src-gen/frontend to src-gen/backend. This is quite a breaking change, but it didn't make any sense that it used to be in the frontend directory in the first place. WDYT?

@msujew
Copy link
Member Author

msujew commented May 24, 2023

@paul-marechal FYI I noticed that webviews weren't working as expected with that approach. They should work now (see a105ab3).

@paul-marechal
Copy link
Member

to simplify the generated electron file, I've moved electron-main from src-gen/frontend to src-gen/backend.

If you want my opinion we should have a src-gen/electron/... directory because it really is its own thing. The preload script could go there too. I agree that the current layout was weird and changing it might be breaking so I'll mention this during the next dev meeting as a heads up. Might want to make a note in the breaking changes section of the changelog too.

@msujew
Copy link
Member Author

msujew commented May 25, 2023

@paul-marechal Generating into src-gen/electron messes kind of with the bundling, since we then need a separated config for the electron-main.js (it currently gets bundled in a single config together with the rest of the application.

Note that I moved some stuff again from backend/bundle to lib/backend and created a lib/frontend for all frontend files. I've updated the breaking changelog 👍

@msujew
Copy link
Member Author

msujew commented May 25, 2023

adapted the main path of the Electron app package to the lib/backend/electron-main.js file.

@sdirix Right, that is necessary in order for the bundled app to work.

Thank you for the feedback by the way. I've done a few changes to the electron build, and it might be more stable now. Are you interested in retesting the issue you were experiencing? Note that a rebuild of the native dependencies needs to be triggered before running theia build.

@msujew msujew added the remote-ssh issues related to the ssh remote functionality label May 31, 2023
@msujew msujew mentioned this pull request May 31, 2023
Copy link
Member

@paul-marechal paul-marechal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM, I can run the examples apps without apparent errors.

Some minor comments left before merging.

CHANGELOG.md Outdated Show resolved Hide resolved
@paul-marechal
Copy link
Member

paul-marechal commented Jun 12, 2023

About having to do theia rebuild:browser or theia rebuild:electron for native dependencies: Since we need to rebuild before bundling, I don't think we can run both example apps build in parallel anymore. Instead the theia rebuild:X command should be issued right before doing the bundling? We can also get rid of the rebuild step before starting the applications since we're using the bundled ones now. WDYT?

@msujew
Copy link
Member Author

msujew commented Jun 13, 2023

@paul-marechal Yes, I agree. I'll update the build scripts 👍

Thanks for the review :)

@msujew msujew added remote issues related to the remote functionality and removed remote-ssh issues related to the ssh remote functionality labels Jun 13, 2023
@pchuong
Copy link
Contributor

pchuong commented Aug 9, 2023

Hello, how do I disable bundling the backend code? Thank you!

@msujew
Copy link
Member Author

msujew commented Aug 9, 2023

@pchuong You can simply remove the bundling config for node, see here.

@pchuong
Copy link
Contributor

pchuong commented Aug 9, 2023

Hi @msujew, I did tried to comment out the line that you have pointed out. And re-run yarn and rebuild the browser example. Calling __dirname in one of my extension, it returns /examples/browser/lib/backend. Using theia v1.36, __dirname returns the lib folder of my extension and not the examples/browser/lib/backend folder.

One additional difference I observe, require.resolve() returns the location of the node_modules folder within the browser example, it used to return the location of the node_module where the exist on disk. It exists in the root node_modules folder.

@msujew
Copy link
Member Author

msujew commented Aug 9, 2023

@pchuong Since you already built the bundled backend once, you'll need to delete the lib/backend folder. The side effects are expected.

@msujew msujew added the bundle Related to webpack bundling label Sep 12, 2023
@lqd1434
Copy link

lqd1434 commented Dec 5, 2023

I experimented with this PR using a non-trivial Theia-based application on Windows 11:

  • Backported the change to Theia 1.34.2
  • Consumed Theia as source in the Theia-based application

We have some manual file system operations in our extensions using __dirname. These were then failing, so I removed them for now. Maybe the webpack build could warn when such constructs are encountered.

Besides that problem and a small hiccup with the generated webpack file I got the Browser variant working. I was successfully able remove the node_modules directory and was still able to run the Theia backend 🎉

However I failed to get the Electron variant to run. For the build I had to add --max-old-space-size=4096 as the Webpack build now required more memory. But even with that out of the way and the build succeeding, Electron immediately crashed with a Javascript error in the main process: "Uncaught Exception: Error: No native build was found for platform=win32 arch=x64 runtime=electron abi=98 uv=1 libc=glibc node=16.5.0 electron=15.5.7 webpack=true loaded from: C:\theia-webpack\apps\electron\lib".

I tried to start the Electron variant with commands like node_modules/.bin/electron.cmd . --app-project-path=. and adapted the main path of the Electron app package to the lib/backend/electron-main.js file.

Do I have to do something different? I was able to start the regular Electron build this way.

i got same error, please tell me how to solve this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bundle Related to webpack bundling remote issues related to the remote functionality theia-cli issues related to the theia-cli
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Bundle Theia backend
6 participants