Webpack не находит модуль vscode при сборке jupyterlab с пользовательским расширением - PullRequest
0 голосов
/ 15 мая 2019

Я пытаюсь создать расширение LSP (Language Server Protocol) для лаборатории jupyter, используя библиотеку vscode-languageclient для машинописи. Модуль vscode-languageclient, кажется, распознается правильно, однако он зависит от модуля vscode, который веб-пакет не находит при создании jupyter lab.

Я добавил модуль vscode в свое расширение, используя

jlpm add vscode

Чтобы заставить jlpm build работать, мне нужно было добавить следующее в мой файл package.json:

"scripts": {
  ...
  "postinstall": "node ./node_modules/vscode/bin/install"
}
"engines": {
    "vscode": "^1.33.x"
}

Это позволило jlpm создать расширение, однако при запуске jupyter lab build я получаю сообщение об ошибке веб-пакета о невозможности найти модуль vscode (см. Вывод терминала).

Я пытался добавить это в мой файл webpack.config.js в промежуточном каталоге jupyter lab перед запуском jupyter lab build:

module.exports {
...
  resolve: {
      alias: {
          vscode$: path.resolve(__dirname, "./node_modules/vscode")
      }
  }
}

Однако это не изменило ошибку.

Это операторы импорта, которые я использую в своем файле index.ts:

import { workspace} from 'vscode';

import {
  LanguageClient,
  LanguageClientOptions,
  ServerOptions,
  TransportKind
} from 'vscode-languageclient';

Это результат работы jupyter lab build:

~$ sudo jupyter lab build
[LabBuildApp] JupyterLab 0.35.5
[LabBuildApp] Cleaning /usr/local/share/jupyter/lab
Cleaning /usr/local/share/jupyter/lab...
Success!
[LabBuildApp] Building in /usr/local/share/jupyter/lab
[LabBuildApp] Node v8.10.0

[LabBuildApp] > /usr/bin/npm pack /home/russell/Uni/FP/Jupy.LSP
Jupy-LSP-0.1.0.tgz
[LabBuildApp] > node /usr/local/lib/python3.6/dist-packages/jupyterlab/staging/yarn.js install
yarn install v1.9.4
info No lockfile found.
[1/5] Validating package.json...
[2/5] Resolving packages...
warning @jupyterlab/application > @jupyterlab/apputils > react > fbjs > core-js@1.2.7: core-js@<2.6.5 is no longer maintained. Please, upgrade to core-js@3 or at least to actual version of core-js@2.
warning css-loader > cssnano > autoprefixer > browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
warning css-loader > cssnano > postcss-merge-rules > browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
warning css-loader > cssnano > postcss-merge-rules > caniuse-api > browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
warning css-loader > cssnano > postcss-merge-rules > postcss-selector-parser > flatten@1.0.2: I wrote this module a very long time ago; you should use something else.
[3/5] Fetching packages...
warning Jupy-LSP@0.1.0: The engine "vscode" appears to be invalid.
warning vscode-languageclient@5.2.1: The engine "vscode" appears to be invalid.
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[4/5] Linking dependencies...
warning "@jupyterlab/vdom-extension > @nteract/transform-vdom@1.1.1" has incorrect peer dependency "react@^15.6.1".
warning "@jupyterlab/vega4-extension > vega-embed > vega-themes@2.3.0" has unmet peer dependency "vega@*".
[5/5] Building fresh packages...
[3/3] ⡀ Jupy-LSP
[-/3] ⡀ waiting...
error /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP: Command failed.
Exit code: 1
Command: node ./node_modules/vscode/bin/install
Arguments: 
Directory: /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP
Output:
module.js:549
    throw err;
    ^

Error: Cannot find module '/usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/node_modules/vscode/bin/install'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)


[LabBuildApp] > node /usr/local/lib/python3.6/dist-packages/jupyterlab/staging/yarn.js run build
yarn run v1.9.4
$ webpack
ModuleNotFoundError: Module not found: Error: Can't resolve 'vscode' in '/usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/lib'
    at factory.create (/usr/local/share/jupyter/lab/staging/node_modules/webpack/lib/Compilation.js:535:10)
    at factory (/usr/local/share/jupyter/lab/staging/node_modules/webpack/lib/NormalModuleFactory.js:397:22)
    at resolver (/usr/local/share/jupyter/lab/staging/node_modules/webpack/lib/NormalModuleFactory.js:130:21)
    at asyncLib.parallel (/usr/local/share/jupyter/lab/staging/node_modules/webpack/lib/NormalModuleFactory.js:224:22)
    at /usr/local/share/jupyter/lab/staging/node_modules/neo-async/async.js:2830:7
    at /usr/local/share/jupyter/lab/staging/node_modules/neo-async/async.js:6877:13
    at normalResolver.resolve (/usr/local/share/jupyter/lab/staging/node_modules/webpack/lib/NormalModuleFactory.js:214:25)
    at doResolve (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:184:12)
    at hook.callAsync (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/usr/local/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at resolver.doResolve (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:37:5)
    at hook.callAsync (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/usr/local/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at hook.callAsync (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/usr/local/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
    at resolver.doResolve (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:42:38)
    at hook.callAsync (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn41 (eval at create (/usr/local/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:28:1)
    at resolver.doResolve (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/ModuleKindPlugin.js:23:37)
    at hook.callAsync (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/usr/local/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at hook.callAsync (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/usr/local/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at args (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/forEachBail.js:30:14)
    at hook.callAsync (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/usr/local/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at resolver.doResolve (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:37:5)
    at hook.callAsync (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/usr/local/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at hook.callAsync (/usr/local/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
resolve 'vscode' in '/usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/lib'
  Parsed request is a module
  using description file: /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/package.json (relative path: ./lib)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/lib/node_modules doesn't exist or is not a directory
      /usr/local/share/jupyter/lab/staging/node_modules/node_modules doesn't exist or is not a directory
      /usr/local/share/jupyter/lab/node_modules doesn't exist or is not a directory
      /usr/local/share/jupyter/node_modules doesn't exist or is not a directory
      /usr/local/share/node_modules doesn't exist or is not a directory
      /usr/local/node_modules doesn't exist or is not a directory
      /usr/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/node_modules
        using description file: /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
      looking for modules in /usr/local/share/jupyter/lab/staging/node_modules
        using description file: /usr/local/share/jupyter/lab/staging/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /usr/local/share/jupyter/lab/staging/node_modules/vscode/package.json (relative path: .)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
          using description file: /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/package.json (relative path: ./node_modules/vscode)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /usr/local/share/jupyter/lab/staging/node_modules/vscode is not a file
            .wasm
              Field 'browser' doesn't contain a valid alias configuration
              /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/node_modules/vscode doesn't exist
            .wasm
              Field 'browser' doesn't contain a valid alias configuration
              /usr/local/share/jupyter/lab/staging/node_modules/vscode.wasm doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/node_modules/vscode.wasm doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /usr/local/share/jupyter/lab/staging/node_modules/vscode.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/node_modules/vscode.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /usr/local/share/jupyter/lab/staging/node_modules/vscode.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/node_modules/vscode.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              /usr/local/share/jupyter/lab/staging/node_modules/vscode.json doesn't exist
              /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/node_modules/vscode.json doesn't exist
            as directory
              /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/node_modules/vscode doesn't exist
            as directory
              existing directory
                using path: /usr/local/share/jupyter/lab/staging/node_modules/vscode/index
                  using description file: /usr/local/share/jupyter/lab/staging/node_modules/vscode/package.json (relative path: ./index)
                    no extension
                      Field 'browser' doesn't contain a valid alias configuration
                      /usr/local/share/jupyter/lab/staging/node_modules/vscode/index doesn't exist
                    .wasm
                      Field 'browser' doesn't contain a valid alias configuration
                      /usr/local/share/jupyter/lab/staging/node_modules/vscode/index.wasm doesn't exist
                    .mjs
                      Field 'browser' doesn't contain a valid alias configuration
                      /usr/local/share/jupyter/lab/staging/node_modules/vscode/index.mjs doesn't exist
                    .js
                      Field 'browser' doesn't contain a valid alias configuration
                      /usr/local/share/jupyter/lab/staging/node_modules/vscode/index.js doesn't exist
                    .json
                      Field 'browser' doesn't contain a valid alias configuration
                      /usr/local/share/jupyter/lab/staging/node_modules/vscode/index.json doesn't exist
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Обратите внимание, что эта ошибка исчезает при удалении вызова postinstall из моего пакета. Json:

error /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP: Command failed.
Exit code: 1
Command: node ./node_modules/vscode/bin/install
Arguments: 
Directory: /usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP
Output:
module.js:549
    throw err;
    ^

Error: Cannot find module '/usr/local/share/jupyter/lab/staging/node_modules/Jupy-LSP/node_modules/vscode/bin/install'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)

К сожалению, это не удаляет / не изменяет последующее сообщение об ошибке.

ОБНОВЛЕНИЕ: Решения, которые я пытался (но не работал):

  • Изменение вызова после установки на
    "postinstall": "node /usr/local/lib/share/jupyter/lab/staging/node_modules/vscode/bin/install" Первая ошибка при сборке jupyter снова исчезает, но веб-пакет все еще не находит vscode
  • Клонирование официального репозитория vscode в модули узлов и использование его вместо
    Компилятор Typescript не находит модуль даже после его переименования в vscode в свой package.json. Похоже, это не было бы намеренным (или стабильным) решением.
  • Использование моноязычного клиента
    Monaco-languageclient зависит от vscode-languageclient и поэтому не работает либо
  • Запуск двоичного кода vscode Compile в модуле узла
    Это дает следующий вывод
$ node bin/compile 
The vscode extension module got updated to TypeScript 2.0.x.
Please see https://code.visualstudio.com/updates/v1_6#_extension-authoring for instruction on how to migrate your extension.

Однако ссылка на самом деле не описывает, как обновить vscode, а содержит информацию о том, какие новые модули включить.

С другой стороны, я проверил всю информацию по содержимому папки vscode и смог найти только эти три файла:
shared.js testrunner.d.ts testrunner.js, которые содержат 42, 44 и 125 LoC. Я не уверен, почему модуль vscode не предоставляет никакой функциональности, но, похоже, это является ядром проблемы.

...