HTML language server crashes with error: Cannot find module 'typescript'

I’m using the following package.json to build theia locally:

{
  "private": true,
  "name": "theia-ide",
  "version": "0.0.0",
  "dependencies": {
    "@theia/core": "latest",
    "@theia/editor": "latest",
    "@theia/filesystem": "latest",
    "@theia/markers": "latest",
    "@theia/messages": "latest",
    "@theia/monaco": "latest",
    "@theia/navigator": "latest",
    "@theia/preferences": "latest",
    "@theia/process": "latest",
    "@theia/terminal": "latest",
    "@theia/workspace": "latest",
    "@theia/plugin-ext": "latest",
    "@theia/plugin-ext-vscode": "latest"
  },
  "devDependencies": {
    "@theia/cli": "latest"
  },
  "theia": {
    "target": "browser"
  },
  "theiaPluginsDir": "plugins",
  "theiaPlugins": {
      "vscode-builtin-html": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/html-1.39.1-prel.vsix",
      "vscode-builtin-html-language-features": "https://open-vsx.org/api/vscode/html-language-features/1.49.0/file/vscode.html-language-features-1.49.0.vsix",
      "vscode-builtin-css": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/css-1.39.1-prel.vsix",
      "vscode-builtin-css-language-features": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/css-language-features-1.39.1-prel.vsix"
  }
}

After building, running theia download:plugins, and starting theia, the language server crashes with the following error shown in the output panel:

Error: Cannot find module 'typescript'
Require stack:
- /home/ben/.theia/plugins/vscode-builtin-html-language-features/extension/server/dist/htmlServerMain.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)
    at Function.Module._load (internal/modules/cjs/loader.js:687:27)
    at Module.require (internal/modules/cjs/loader.js:903:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/ben/.theia/plugins/vscode-builtin-html-language-features/extension/server/dist/htmlServerMain.js:1:546200)
    at n (/home/ben/.theia/plugins/vscode-builtin-html-language-features/extension/server/dist/htmlServerMain.js:1:158)
    at Object.<anonymous> (/home/ben/.theia/plugins/vscode-builtin-html-language-features/extension/server/dist/htmlServerMain.js:1:538440)
    at n (/home/ben/.theia/plugins/vscode-builtin-html-language-features/extension/server/dist/htmlServerMain.js:1:158)
    at Object.<anonymous> (/home/ben/.theia/plugins/vscode-builtin-html-language-features/extension/server/dist/htmlServerMain.js:1:532782)
    at n (/home/ben/.theia/plugins/vscode-builtin-html-language-features/extension/server/dist/htmlServerMain.js:1:158) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/ben/.theia/plugins/vscode-builtin-html-language-features/extension/server/dist/htmlServerMain.js'
  ]
}

I’ve tried running yarn add typescript and rebuilding, but the HTML LS still fails with the same error. Has anyone run into this before? Is typescript supposed to be installed somewhere else?

Hi! Try adding "typescript": "latest" to your devDependencies.

@mnaglic I’ve tried adding typescript to both dependencies and devDependencies, and I still get the same error.

@bendavis it may be related to the following issue: https://github.com/theia-ide/vscode-builtin-extensions/issues/33. Do you mind verifying with the version referenced in the issue:

@vince-fugnitto I tried with that updated version as well and still ran into the same issue. Are you able to reproduce? Here’s the package.json I’m testing with:

{
  "private": true,
  "name": "theia-ide",
  "version": "0.0.0",
  "dependencies": {
    "@theia/core": "latest",
    "@theia/editor": "latest",
    "@theia/filesystem": "latest",
    "@theia/markers": "latest",
    "@theia/messages": "latest",
    "@theia/monaco": "latest",
    "@theia/navigator": "latest",
    "@theia/plugin-ext": "latest",
    "@theia/plugin-ext-vscode": "latest",
    "@theia/preferences": "latest",
    "@theia/process": "latest",
    "@theia/terminal": "latest",
    "@theia/workspace": "latest",
    "typescript": "latest"
  },
  "devDependencies": {
    "@theia/cli": "latest",
    "typescript": "latest"
  },
  "theia": {
    "target": "browser"
  },
  "theiaPluginsDir": "plugins",
  "theiaPlugins": {
    "vscode-builtin-html": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/html-1.39.1-prel.vsix",
    "vscode-builtin-html-language-features": "https://open-vsx.org/api/vscode/html-language-features/1.48.0-next.4a1bcdafe9/file/vscode.html-language-features-1.48.0-next.4a1bcdafe9.vsix",
    "vscode-builtin-css": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/css-1.39.1-prel.vsix",
    "vscode-builtin-css-language-features": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/css-language-features-1.39.1-prel.vsix"
  }
}

I’m building using the following steps (starting with just package.json):

$ nvm use 12
$ yarn --pure-lockfile
$ yarn theia build
$ yarn theia download:plugins
$ yarn --production
$ node src-gen/backend/main.js /tmp/test-project --hostname=0.0.0.0

I figured out what was wrong. I did not have $THEIA_DEFAULT_PLUGINS set, and it was pulling plugins from ~/.theia/plugins instead of the local plugins dir, so it was using the older version.

After making sure I’m using the newer version of html-language-features and making sure it was using the correct plugins dir, it worked correctly.