使用自定义扩展构建jupyterlab时,Webpack找不到模块vscode

时间:2019-05-15 18:06:55

标签: typescript webpack visual-studio-code yarnpkg jupyter-lab

我正尝试使用vscode-languageclient库作为打字稿,为jupyter实验室构建LSP(语言服务器协议)扩展。 vscode-languageclient模块似乎可以正确识别,但是它依赖于vscode模块,在构建jupyter实验室时webpack找不到该模块。

我已使用

将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时,我收到一个Webpack错误,提示它无法定位模块vscode(请参阅终端输出)。

在运行jupyter lab build之前,我尝试将其添加到jupyter lab的登台目录中的webpack.config.js文件中:

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

但是,它并没有改变错误。

这些是我在index.ts文件中使用的import语句:

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.

请注意,从我的package.json中删除postinstall调用时,此错误消失了:

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)

不幸的是,这不会删除/更改随后的错误消息。

0 个答案:

没有答案