title: Webpack does not find module vscode when building jupyterlab with custom extension
body: <p>I'm trying to build a LSP (Language Server Protocol) extension for jupyter lab, using the vscode-languageclient library for typescript. The vscode-languageclient module seems to be recognized correctly, however it is dependent on the vscode module, which webpack does not find when building jupyter lab.</p>
  
  <p>I have added the vscode module to my extension using    </p>
  
  <p><code>jlpm add vscode</code></p>
  
  <p>To get <code>jlpm build</code> to work, i had to add the following to my package.json file:</p>
  
  <pre><code>"scripts": {
    ...
    "postinstall": "node ./node_modules/vscode/bin/install"
  }
  "engines": {
      "vscode": "^1.33.x"
  }
  </code></pre>
  
  <p>This made it possible for jlpm to build the extension, however when running <code>jupyter lab build</code> I get a webpack error about it not being able to locate the module vscode (see terminal output).</p>
  
  <p>I have tried adding this to my webpack.config.js file in the staging directory of jupyter lab before running <code>jupyter lab build</code>:</p>
  
  <pre><code>module.exports {
  ...
    resolve: {
        alias: {
            vscode$: path.resolve(__dirname, "./node_modules/vscode")
        }
    }
  }
  </code></pre>
  
  <p>However, it did not change the error.</p>
  
  <p>These are the import statements I use in my index.ts file:</p>
  
  <pre><code>import { workspace} from 'vscode';
  
  import {
    LanguageClient,
    LanguageClientOptions,
    ServerOptions,
    TransportKind
  } from 'vscode-languageclient';
  </code></pre>
  
  <p>This is the output of running <code>jupyter lab build</code>:</p>
  
  <pre><code>~$ 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] &gt; /usr/bin/npm pack /home/russell/Uni/FP/Jupy.LSP
  Jupy-LSP-0.1.0.tgz
  [LabBuildApp] &gt; 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 &gt; @jupyterlab/apputils &gt; react &gt; fbjs &gt; core-js@1.2.7: core-js@&lt;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 &gt; cssnano &gt; autoprefixer &gt; browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist &gt;3.0 config used in other tools.
  warning css-loader &gt; cssnano &gt; postcss-merge-rules &gt; browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist &gt;3.0 config used in other tools.
  warning css-loader &gt; cssnano &gt; postcss-merge-rules &gt; caniuse-api &gt; browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist &gt;3.0 config used in other tools.
  warning css-loader &gt; cssnano &gt; postcss-merge-rules &gt; postcss-selector-parser &gt; 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 &gt; @nteract/transform-vdom@1.1.1" has incorrect peer dependency "react@^15.6.1".
  warning "@jupyterlab/vega4-extension &gt; vega-embed &gt; 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] &gt; 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), &lt;anonymous&gt;: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), &lt;anonymous&gt;: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), &lt;anonymous&gt;: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), &lt;anonymous&gt;: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), &lt;anonymous&gt;: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), &lt;anonymous&gt;: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), &lt;anonymous&gt;: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), &lt;anonymous&gt;: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.
  </code></pre>
  
  <p>Note that this error disappears when removing the postinstall call from my package.json:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Unfortunately, this does not remove/change the subsequent error message.</p>
  
  <p>UPDATE: Solutions I have tried (but didn't work):  </p>
  
  <ul>
  <li>Changing the postinstall call to<br>
  <code>"postinstall": "node /usr/local/lib/share/jupyter/lab/staging/node_modules/vscode/bin/install"</code>
  The first error when building jupyter disappears again, but webpack still doesn't find vscode</li>
  <li>Cloning the <a href="https://github.com/microsoft/vscode" rel="nofollow noreferrer">official vscode repository</a> into node modules and using that instead<br>
  The Typescript compiler doesn't find the module, even after renaming it to vscode in its package.json. This doesn't seem like it would be an intended (or stable) solution anyway.</li>
  <li>Using the <a href="https://github.com/TypeFox/monaco-languageclient" rel="nofollow noreferrer">monaco-languageclient</a><br>
  The monaco-languageclient is dependent on the vscode-languageclient and therefore doesn't work either  </li>
  <li>Running the vscode Compile binary in the node module<br>
  This gives the following output</li>
  </ul>
  
  <pre><code>$ 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.
  </code></pre>
  
  <p>However, the link doesn't actually adress how to upgrade vscode but rather which new modules to include.  </p>
  
  <p>On another note, I've searched the whole vscode folder for acutal code contents and could only find these three files:<br>
  <code>shared.js  testrunner.d.ts  testrunner.js</code>, which contain 42, 44 and 125 LoC. I am not sure why the vscode module provides no functionality, but this seems to be the core of the problem.</p>