theia: Error: Cannot find module '@theia/test/lib/common/collections'

Bug Description:

2023-12-05T16:06:44.296Z root WARN Frontend J.configure took longer than the expected maximum 100 milliseconds: 101.0 ms [Finished 1.026 s after frontend start]
2023-12-05T16:06:44.312Z root WARN A command editor.action.toggleStickyScroll is already registered.
2023-12-05T16:06:44.415Z root INFO Start frontend contributions: 239.0 ms [Finished 1.126 s after frontend start]
2023-12-05T16:06:44.415Z root INFO Changed application state from 'init' to 'started_contributions'.
2023-12-05T16:06:44.418Z root INFO Changed application state from 'started_contributions' to 'attached_shell'.
2023-12-05T16:06:44.418Z root INFO >>> Restoring the layout state...
2023-12-05T16:06:44.491Z root WARN Linked preference "workbench.colorCustomizations" not found.
2023-12-05T16:06:44.491Z root WARN Linked preference "window.titleBarStyle" not found.
2023-12-05T16:06:44.499Z root INFO [1edff308-3191-438b-9746-f02478f02d38] Waiting for backend deployment: 139.0 ms [Finished 1.264 s after frontend start]
2023-12-05T16:06:44.531Z root INFO [1edff308-3191-438b-9746-f02478f02d38] Sync of 1 plugin: 30.0 ms [Finished 1.294 s after frontend start]
2023-12-05T16:06:44.629Z root ERROR [hosted-plugin: 40] node:internal/modules/cjs/loader:1080
  throw err;
  ^

Error: Cannot find module '@theia/test/lib/common/collections'
Require stack:
- /opt/theia/node_modules/@theia/plugin-ext/lib/plugin/test-item.js
- /opt/theia/node_modules/@theia/plugin-ext/lib/plugin/tests.js
- /opt/theia/node_modules/@theia/plugin-ext/lib/plugin/plugin-context.js
- /opt/theia/node_modules/@theia/plugin-ext/lib/plugin/plugin-manager.js
- /opt/theia/node_modules/@theia/plugin-ext/lib/hosted/node/plugin-host-rpc.js
- /opt/theia/node_modules/@theia/plugin-ext/lib/hosted/node/plugin-host.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (/opt/theia/node_modules/@theia/plugin-ext/lib/plugin/test-item.js:28:23)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/opt/theia/node_modules/@theia/plugin-ext/lib/plugin/test-item.js',
    '/opt/theia/node_modules/@theia/plugin-ext/lib/plugin/tests.js',
    '/opt/theia/node_modules/@theia/plugin-ext/lib/plugin/plugin-context.js',
    '/opt/theia/node_modules/@theia/plugin-ext/lib/plugin/plugin-manager.js',
    '/opt/theia/node_modules/@theia/plugin-ext/lib/hosted/node/plugin-host-rpc.js',
    '/opt/theia/node_modules/@theia/plugin-ext/lib/hosted/node/plugin-host.js'
  ]
}

Node.js v18.16.1
2023-12-05T16:06:44.631Z root ERROR [hosted-plugin: 40] IPC exited, with signal: null, and exit code: 1
2023-12-05T16:06:44.702Z root WARN Preference security.workspace.trust.enabled in file:///home/project/code/.theia/settings.json can only be defined in scopes: Default, User, Workspace.
2023-12-05T16:06:44.702Z root WARN Preference preview.openByDefault in file:///home/project/code/.theia/settings.json can only be defined in scopes: Default, User, Workspace.
2023-12-05T16:06:44.871Z root INFO <<< The layout has been successfully restored.
2023-12-05T16:06:44.877Z root INFO Initialize the workbench layout: 488.0 ms [Finished 1.635 s after frontend start]
2023-12-05T16:06:44.878Z root INFO Changed application state from 'attached_shell' to 'initialized_layout'.
2023-12-05T16:06:44.878Z root INFO [1edff308-3191-438b-9746-f02478f02d38] Loading plugin contributions
2023-12-05T16:06:44.878Z root INFO [1edff308-3191-438b-9746-f02478f02d38] Load contributions of 1 plugin: 6.0 ms [Finished 1.641 s after frontend start]
2023-12-05T16:06:45.693Z root INFO Frontend application start: 1461.3 ms [Finished 34.263 s after backend start]
2023-12-05T16:06:45.693Z root INFO Replace loading indicator with ready workbench UI (animation): 813.0 ms [Finished 2.456 s after frontend start]
2023-12-05T16:06:45.694Z root INFO Changed application state from 'initialized_layout' to 'ready'.

Steps to Reproduce:

  1. Build a Docker image using the files identified below.
  2. Create a Docker container and connect to is using a web browser.
  3. Observe error.

Dockerfile

FROM node:18.16

# Setting DEBIAN_FRONTEND=noninteractive prevents warnings about UI dialogs
ENV DEBIAN_FRONTEND=noninteractive
# Installing apt-utils early prevents warnings about deferred operations
RUN apt update && apt upgrade -y && apt install -y apt-utils 

# -----------------------------------------------------------------------------
# Locale and Timezone
ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
RUN apt install -y locales locales-all tzdata && \
  ln -fs /usr/share/zoneinfo/America/Los_Angeles /etc/localtime && \
  dpkg-reconfigure --frontend noninteractive tzdata

# -----------------------------------------------------------------------------
# Install Node.js, Yarn, and other prerequisites
# https://github.com/eclipse-theia/theia/blob/master/doc/Developing.md#prerequisites
RUN apt install -y --no-install-recommends \
  make build-essential libsecret-1-dev libx11-dev libxkbfile-dev pkg-config

# -----------------------------------------------------------------------------
# install Theia
WORKDIR /opt/theia
ENV THEIA_DEFAULT_PLUGINS=local-dir:/opt/theia/plugins
ENV THEIA_PLUGINS=local-dir:/home/project/.theia/plugins
ADD package.json ./

######### This causes things to break! ##########
ADD code-runner-0.12.1.vsix /opt/theia/plugins/

# so that this works on macOS
RUN if [ `uname -m` = "aarch64" ]; \
    then apt install chromium -y; \
  fi
RUN NODE_OPTIONS="--max_old_space_size=4000" yarn install --pure-lockfile
RUN yarn theia download:plugins
RUN NODE_OPTIONS="--max_old_space_size=8000" yarn theia build
# create production lockfile and delete everything not in it
RUN yarn install --production && \
  yarn autoclean --init && \
  echo "*.ts\n*.ts.map\n*.spec.*\n" >> .yarnclean && \
  yarn autoclean --force && \
  yarn cache clean

# Add my host user ID to the guest system
RUN echo "user501:x:501:100::/home/project:/bin/bash" > users.txt; \
  newusers users.txt && rm users.txt

ADD start.sh /usr/local/bin/
RUN mkdir -p "/home/project/code"
ENV SHELL /bin/bash
ENTRYPOINT ["/usr/local/bin/start.sh"]
EXPOSE 3000
ENV CODE_PATH /home/project/code
USER user501

# -----------------------------------------------------------------------------
# Build and run commands

# docker builder prune -af && docker container prune -f && docker image prune -af 
# docker build -t theia-common workspaces/common/
# docker build -t theia-common --progress=plain workspaces/common/
# docker run --rm -it --entrypoint bash theia-common
# docker run --rm -it --hostname code -p 3000:3000 -u $UID:100 -e "LDAPUNAME=$USER" -v "/Users/jfoster/temp/theia:/home/project:cached" theia-common
# curl -v localhost:3000

package.json

{
  "private": true,
  "dependencies": {
    "@theia/callhierarchy": "latest",
    "@theia/file-search": "latest",
    "@theia/git": "latest",
    "@theia/markers": "latest",
    "@theia/messages": "latest",
    "@theia/navigator": "latest",
    "@theia/outline-view": "latest",
    "@theia/plugin-ext-vscode": "latest",
    "@theia/preferences": "latest",
    "@theia/preview": "latest",
    "@theia/search-in-workspace": "latest",
    "@theia/terminal": "latest",
    "@theia/vsx-registry": "latest"
  },
  "devDependencies": {
    "@theia/cli": "latest"
  },
  "scripts": {
    "prepare": "yarn run clean && yarn build && yarn run download:plugins",
    "clean": "theia clean",
    "build": "theia build --mode development",
    "start": "theia start --plugins=local-dir:plugins",
    "download:plugins": "theia download:plugins"
  },
  "theiaPluginsDir": "plugins"
}

start.sh

#!/bin/bash

node /opt/theia/src-gen/backend/main.js --hostname 0.0.0.0 "${CODE_PATH}"

Additional Information

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

I can confirm that it works when I comment out the test statements in the .yarnclean file.

File: .yarnclean

# test directories
#__tests__
#test
#tests
#powered-test

# asset directories
docs
doc
website
images
assets

# examples
example
examples

# code coverage directories
coverage
.nyc_output

# build scripts
Makefile
Gulpfile.js
Gruntfile.js

# configs
appveyor.yml
circle.yml
codeship-services.yml
codeship-steps.yml
wercker.yml
.tern-project
.gitattributes
.editorconfig
.*ignore
.eslintrc
.jshintrc
.flowconfig
.documentup.json
.yarn-metadata.json
.travis.yml

# misc
*.md
*.ts
*.ts.map
*.spec.*

@jgfoster I believe it is the result of the yarn autoclean --force command which removes @theia/test due to test being the name of the directory. You can confirm by omitting the clean command. It’s not related to docker or plugins in this case.

.yarnclean looks something like (after yarn autoclean --init):

# test directories
__tests__
test
tests
powered-test
...