Failed to resolve module: @theia/electron

this is error log.
#13 300.4 warning “@theia/debug > requestretry@7.1.0” has unmet peer dependency “request@2..”.
#13 300.4 warning “@theia/debug > @theia/process > node-pty@0.11.0-beta17” has unmet peer dependency “node-gyp@^8.3.0”.
#13 300.4 warning “@theia/messages > react-perfect-scrollbar@1.5.8” has unmet peer dependency “react@>=16.3.3”.
#13 300.4 warning “@theia/messages > react-perfect-scrollbar@1.5.8” has unmet peer dependency “react-dom@>=16.3.3”.
#13 300.4 warning “@theia/plugin-ext > @theia/scm > react-autosize-textarea@7.1.0” has unmet peer dependency “react@^0.14.0 || ^15.0.0 || ^16.0.0”.
#13 300.4 warning “@theia/plugin-ext > @theia/scm > react-autosize-textarea@7.1.0” has unmet peer dependency “react-dom@^0.14.0 || ^15.0.0 || ^16.0.0”.
#13 304.8 [4/4] Building fresh packages…
#13 398.7 Done in 398.45s.
#13 398.9 yarn run v1.22.5
#13 398.9 $ /home/theia/node_modules/.bin/theia build
#13 399.4 Failed to resolve module: @theia/electron
#13 412.8 Error: webpack exited with an unexpected signal: SIGKILL.
#13 412.8 at ChildProcess. (/home/theia/node_modules/@theia/application-manager/lib/application-process.js:59:28)
#13 412.8 at ChildProcess.emit (events.js:400:28)
#13 412.8 at maybeClose (internal/child_process.js:1058:16)
#13 412.8 at Process.ChildProcess._handle.onexit (internal/child_process.js:293:5)
#13 413.6 error Command failed with exit code 1.

this is package.json

{
    "private": true,
    "theia": {
        "frontend": {
            "config": {
                "applicationName": "Theia Multi-Language Example",
                "preferences": {
                    "files.enableTrash": false,
                    "ruby.useLanguageServer": true,
                    "php.suggest.basic": false
                }
            }
        }
    },
    "dependencies": {
        "@theia/callhierarchy": "1.34.0",
        "@theia/console": "1.34.0",
        "@theia/core": "1.34.0",
        "@theia/debug": "1.34.0",
        "@theia/editor": "1.34.0",
        "@theia/editor-preview": "1.34.0",
        "@theia/file-search": "1.34.0",
        "@theia/filesystem": "1.34.0",
        "@theia/getting-started": "1.34.0",
        "@theia/keymaps": "1.34.0",
        "@theia/markers": "1.34.0",
        "@theia/messages": "1.34.0",
        "@theia/metrics": "1.34.0",
        "@theia/monaco": "1.34.0",
        "@theia/navigator": "1.34.0",
        "@theia/outline-view": "1.34.0",
        "@theia/output": "1.34.0",
        "@theia/plugin": "1.34.0",
        "@theia/plugin-ext": "1.34.0",
        "@theia/plugin-ext-vscode": "1.34.0",
        "@theia/preferences": "1.34.0",
        "@theia/process": "1.34.0",
        "@theia/scm": "1.34.0",
        "@theia/search-in-workspace": "1.34.0",
        "@theia/task": "1.34.0",
        "@theia/terminal": "1.34.0",
        "@theia/typehierarchy": "1.34.0",
        "@theia/userstorage": "1.34.0",
        "@theia/variable-resolver": "1.34.0",
        "@theia/vsx-registry": "1.34.0",
        "@theia/workspace": "1.34.0"
    },
    "devDependencies": {
        "@theia/cli": "1.34.0"
    },
    "scripts": {
        "preinstall": "node-gyp install"
    },
    "theiaPluginsDir": "plugins",
}

i delete theia plugin,because i can’t add three link.

Hey @zbm0711,

This is the actual error that prevents the build from successfully finishing, the Failed to resolve module: @theia/electron is just an unrelated warning (though I’m suprised that it appears at all).

The webpack error only occurs if you don’t have enough memory available to build Theia. Due to it’s relatively large codebase, Theia requires roughly 3GB of memory to build. Do you have that much available on your machine/docker image? Otherwise you can manually increase the memory allowed to be used by the node process by using the --max-old-space-size=8192 argument, which increases the memory to 8GB.

1 Like

Problem solved, thanks for help.

Hi,
where did you set --max-old-space-size=8192 in your project? is it in project.json? could you give me a little code snap, I have the same memory problem

@wss It’s supposed to be used as an argument for the yarn process.

hey, @msujew ,
I do this but the error still occurs.
This is my Dockerfile:

ARG NODE_VERSION=16.14.2
FROM node:${NODE_VERSION}-alpine
RUN apk add --no-cache make pkgconfig gcc g++ python3 libx11-dev libxkbfile-dev libsecret-dev
ARG version=latest
WORKDIR /home/theia
ADD $version.package.json ./package.json
ADD ./widget-extension/ widget-extension
ARG GITHUB_TOKEN
RUN yarn --pure-lockfile && \
    NODE_OPTIONS="--max_old_space_size=8192" yarn theia build && \
    yarn theia download:plugins && \
    yarn --production && \
    yarn autoclean --init && \
    echo *.ts >> .yarnclean && \
    echo *.ts.map >> .yarnclean && \
    echo *.spec.* >> .yarnclean && \
    yarn autoclean --force && \
    yarn cache clean

FROM node:${NODE_VERSION}-alpine
# See : https://github.com/theia-ide/theia-apps/issues/34
RUN addgroup theia && \
    adduser -G theia -s /bin/sh -D theia;
RUN chmod g+rw /home && \
    mkdir -p /home/project && \
    chown -R theia:theia /home/theia && \
    chown -R theia:theia /home/project;
RUN apk add --no-cache git openssh bash libsecret
ENV HOME /home/theia
WORKDIR /home/theia
COPY --from=0 --chown=theia:theia /home/theia /home/theia
EXPOSE 3000
ENV SHELL=/bin/bash \
    THEIA_DEFAULT_PLUGINS=local-dir:/home/theia/plugins
ENV USE_LOCAL_GIT true
USER theia
ENTRYPOINT [ "node", "/home/theia/src-gen/backend/main.js", "/home/project", "--hostname=0.0.0.0" ]

this is error log

#0 445.6 ERROR in ./node_modules/@theia/core/electron-shared/electron/index.js 1:0-59
#0 445.6 Module not found: Error: Can't resolve '@theia/electron/shared/electron' in '/home/theia/node_modules/@theia/core/electron-shared/electron'
#0 445.6 resolve '@theia/electron/shared/electron' in '/home/theia/node_modules/@theia/core/electron-shared/electron'
#0 445.6   Parsed request is a module
#0 445.6   using description file: /home/theia/node_modules/@theia/core/package.json (relative path: ./electron-shared/electron)
#0 445.6     resolve as module
#0 445.6       /home/theia/node_modules/@theia/core/electron-shared/electron/node_modules doesn't exist or is not a directory
#0 445.6       /home/theia/node_modules/@theia/core/electron-shared/node_modules doesn't exist or is not a directory
#0 445.6       looking for modules in /home/theia/node_modules/@theia/core/node_modules
#0 445.6         /home/theia/node_modules/@theia/core/node_modules/@theia/electron doesn't exist
#0 445.6       /home/theia/node_modules/@theia/node_modules doesn't exist or is not a directory
#0 445.6       /home/theia/node_modules/node_modules doesn't exist or is not a directory
#0 445.6       looking for modules in /home/theia/node_modules
#0 445.6         /home/theia/node_modules/@theia/electron doesn't exist
#0 445.6       /home/node_modules doesn't exist or is not a directory
#0 445.6       /node_modules doesn't exist or is not a directory
#0 445.6  @ ./node_modules/@theia/filesystem/lib/electron-browser/preload.js 21:19-66
#0 445.6  @ ./src-gen/frontend/preload.js 4:0-65
#0 445.6 
#0 445.6 webpack 5.81.0 compiled with 1 error in 4300 ms
#0 445.6 
#0 446.0 Error: webpack exited with an unexpected code: 1.
#0 446.0     at ChildProcess.<anonymous> (/home/theia/node_modules/@theia/application-manager/lib/application-process.js:66:28)
#0 446.0     at ChildProcess.emit (node:events:526:28)
#0 446.0     at maybeClose (node:internal/child_process:1092:16)
#0 446.0     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
#0 446.2 error Command failed with exit code 1.
#0 446.2 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
------
Dockerfile:9
--------------------
   8 |     ARG GITHUB_TOKEN
   9 | >>> RUN yarn --pure-lockfile && \
  10 | >>>     NODE_OPTIONS=--max_old_space_size=8192 yarn theia build && \
  11 | >>>     yarn theia download:plugins && \
  12 | >>>     yarn --production && \
  13 | >>>     yarn autoclean --init && \
  14 | >>>     echo *.ts >> .yarnclean && \
  15 | >>>     echo *.ts.map >> .yarnclean && \
  16 | >>>     echo *.spec.* >> .yarnclean && \
  17 | >>>     yarn autoclean --force && \
  18 | >>>     yarn cache clean
  19 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c yarn --pure-lockfile &&     NODE_OPTIONS=--max_old_space_size=8192 yarn theia build &&     yarn theia download:plugins &&     yarn --production &&     yarn autoclean --init &&     echo *.ts >> .yarnclean &&     echo *.ts.map >> .yarnclean &&     echo *.spec.* >> .yarnclean &&     yarn autoclean --force &&     yarn cache clean" did not complete successfully: exit code: 1
error Command failed with exit code 1.

@XiaoYi-byte I’m not sure whether Theia correctly passes the env variables to webpack. You might want to pass them to the process as arguments instead:

yarn theia build --max_old_space_size=8192

@msujew Thank you for your reply.
I change my RUN command in Dockerfile:

RUN yarn --pure-lockfile && \
    yarn theia build --max_old_space_size=8192 && \
    yarn theia download:plugins && \
    yarn --production && \
    yarn autoclean --init && \
    echo *.ts >> .yarnclean && \
    echo *.ts.map >> .yarnclean && \
    echo *.spec.* >> .yarnclean && \
    yarn autoclean --force && \
    yarn cache clean

Then I run “docker build” command, it shows errors like this:

#0 312.5 $ /home/theia/node_modules/.bin/theia build --max_old_space_size=8192
#0 313.3 Failed to resolve module: @theia/electron
#0 313.5 [webpack-cli] Error: Unknown option '--max_old_space_size=8192'
#0 313.5 
#0 313.5 [webpack-cli] Run 'webpack --help' to see available commands and options
#0 313.5 
#0 313.6 Error: webpack exited with an unexpected code: 2.
#0 313.6     at ChildProcess.<anonymous> (/home/theia/node_modules/@theia/application-manager/lib/application-process.js:66:28)
#0 313.6     at ChildProcess.emit (node:events:526:28)
#0 313.6     at maybeClose (node:internal/child_process:1092:16)
#0 313.6     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
#0 313.6 error Command failed with exit code 1.
#0 313.6 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
------
Dockerfile:9
--------------------
   8 |     ARG GITHUB_TOKEN
   9 | >>> RUN yarn --pure-lockfile && \
  10 | >>>     yarn theia build --max_old_space_size=8192 && \
  11 | >>>     yarn theia download:plugins && \
  12 | >>>     yarn --production && \
  13 | >>>     yarn autoclean --init && \
  14 | >>>     echo *.ts >> .yarnclean && \
  15 | >>>     echo *.ts.map >> .yarnclean && \
  16 | >>>     echo *.spec.* >> .yarnclean && \
  17 | >>>     yarn autoclean --force && \
  18 | >>>     yarn cache clean
  19 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c yarn --pure-lockfile &&     yarn theia build --max_old_space_size=8192 &&     yarn theia download:plugins &&     yarn --production &&     yarn autoclean --init &&     echo *.ts >> .yarnclean &&     echo *.ts.map >> .yarnclean &&     echo *.spec.* >> .yarnclean &&     yarn autoclean --force &&     yarn cache clean" did not complete successfully: exit code: 1
error Command failed with exit code 1.

Nevermind, I didn’t look too closely at your original comment. It’s not about the memory, but rather about a missing electron dependency.

It seems like you’re trying to bundle an Electron app in a docker image? You should only build the browser application in the docker image.

I am trying to build a browser application in the docker image and I don’t need dependencies related to Electron. But I don’t know how to remove Electron in the build process. Could you tell me something about this?

@XiaoYi-byte thank you for reporting the issue, you actually encountered regression: unable to build browser-only application · Issue #12490 · eclipse-theia/theia · GitHub which should be fixed by move preload bits under Electron only by paul-marechal · Pull Request #12491 · eclipse-theia/theia · GitHub.

In the meantime (until a patch release is ready) you should be able to use v1.36.0.

I think a workaround would be to go in webpack.config.js and add logic to delete the config entry that tries to bundle preload.js. Fortunately it seems like it’s the last element in the config array, so it’s less than ideal but doing config.pop() should solve the issue for now.

@vince-fugnitto OK, thank you for your reply.

Just an FYI, we performed a patch release v1.37.1 which fixes the regression.