2

I am trying to create a playground using monaco-editor and vscode-languageserver to show the features of my language server.

However when I try to import 'vscode-languageserver' from a page like the following example

//# src/pages/test.js 
const { TextDocument } =  require("vscode-languageserver"); 
console.log(TextDocument.create('a' , 'b' , 'c' , 'd' )); 

https://github.com/zkrami/docusaurus-test/blob/master/src/pages/test.js

I get the following errors:

Module not found: Can't resolve 'child_process' in 'C:\Users\Rami\git\my-website\node_modules\vscode-languageserver\lib'./node_modules/vscode-languageserver/lib/files.js

Module not found: Can't resolve 'fs' in 'C:\Users\Rami\git\my-website\node_modules\vscode-languageserver\lib'./node_modules/vscode-jsonrpc/lib/pipeSupport.js

and please note that if I imported the module in the docusaurus.config.js file it works perfectly.

I made a quick example you can try: https://github.com/zkrami/docusaurus-test/

Specifications:

yarn 1.22.4 
node v10.15.3
OS: Windows
@docusaurus/core: "^2.0.0-alpha.54"
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
Rami ZK
  • 510
  • 3
  • 13

2 Answers2

1

I ended up using vscode-languageserver-protocol package which fulfill my requirements.

Rami ZK
  • 510
  • 3
  • 13
0

fs is a Node module and requires Node runtime, you can't use it in the browser.

This is not a Docusaurus issue, you wouldn't be able to use it in any client-side React app.

Yangshun Tay
  • 49,270
  • 33
  • 114
  • 141
  • I don't attend to use `fs` itself but the `vscode-languageserver` require it for certain functionalities which I am not using. – Rami ZK May 10 '20 at 19:13
  • in addition I am using the same package in another react-app and it's working well. I also tried it with Docusaurus v1 and it worked just fine. – Rami ZK May 10 '20 at 19:16
  • Do you have a code example of how the client work with the server? It seems like it is not very well documented. Thanks. – lcb Oct 13 '21 at 19:03