[Solved] ModuleNotFound error in vscode-ide-purescript, connection failed

I just found one of my 3 projects shows warnings like this https://github.com/Cirru/parser.purs . While the same VS code works correctly in other 2 projects. Tried restarting many times and there are still same warning on every PureScript file inside this project.

got some logs from VS Code output:

[Info  - 1:55:54 AM] /usr/local/bin/purs: 0.14.0

[Warn  - 1:55:54 AM] Found multiple IDE server executables; using /Users/chen/.config/yarn/global/node_modules/.bin/purs
[Info  - 1:55:54 AM] Starting IDE server on port 15995 with cwd /Users/chen/repo/cirru/parser.purs
Started IDE server (port 15995)
[Info  - 1:55:54 AM] Retrying starting server after 500ms: Error: connect ECONNREFUSED
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
[Info  - 1:55:55 AM] [Info] cachedb was changed from: Nothing, to: Just 2021-04-06 17:55:17.705537979 UTC @(main:Command.Ide app/Command/Ide.hs:205:25)

[Info  - 1:55:57 AM] [Error] Version mismatch for the externs at: /Users/chen/repo/cirru/parser.purs/output/Data.Ord.Unsafe/externs.cbor Expected: 0.14.0 Found: 0.13.8

[Info  - 1:55:57 AM] Non-fatal error loading modules: Version mismatch for the externs at: /Users/chen/repo/cirru/parser.purs/output/Data.Ord.Unsafe/externs.cbor Expected: 0.14.0 Found: 0.13.8
Built with 9/9 issues for file: "/Users/chen/repo/cirru/parser.purs/test/Main.purs", all diagnostic files: ["/Users/chen/repo/cirru/parser.purs/test/Main.purs"]
(Just { textDocument: { codeAction: { codeActionLiteralSupport: { codeActionKind: { valueSet: [CodeActionKind ,CodeActionKind quickfix,CodeActionKind refactor,CodeActionKind refactor.extract,CodeActionKind refactor.inline,CodeActionKind refactor.rewrite,CodeActionKind source,CodeActionKind source.organizeImports] } }, isPreferredSupport: true } }, workspace: { applyEdit: true, workspaceEdit: { documentChanges: true } } })
Literals supported: (Just true)

the errors look quite similar to ModuleNotFound error in vscode-ide-purescript but I tried reloading many times, it doesn’t work.

I also wondering if purs compile is involved in this process when I press “Command s” and it checks the code, since the docs mentioned about it. But as I tried, my other projects will show “module not found” errors as well, I guess this command is not used in this way…

pity that there’s not more information about why the connection failed. I can always find the process running but it cannot be connected to:

[Info  - 1:55:54 AM] Retrying starting server after 500ms: Error: connect ECONNREFUSED
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)

I also tried PureScript: Build it seems to work fine and it eliminates the errors generated by pressing “Save”.

tried again and again and I noticed it mentioned output folder as well… and finally fixed the problem.

Deleting the output and .spago folders resolved my version of the issue.

but why output always contains the invalid code even after I rerun spago build, deleting .spago/, after so many steps…

Whenever I’ve had “module not found” errors it’s because the version of purs you used to build the project is different than the version running in the ide. Make sure you are using the same purs binaries. If you locally install purs with npm, then I think there is a config option for the ide plugin to use the locally installed purs.

1 Like

This is the relevant output that tells you you’re using mismatched purs binaries. Probably one on your PATH and one from npm


so my doubt is why code in output/ as not updated. I ran spago build many times, but it didn’t update until I removed the whole folder and build again.

and it shew now warnings when I run spago build in command line, instead it show in VS Code. so how it vscode-ide-purescript building, is it using purs compile directly?

Do have any configuration for purs in your .vscode\settings.json (or in global config)?

It is not vscode-ide-purescript directly but language-purescript (LS) who is responsible for building, it uses spago build.

This is actually a little bit nasty problem with configuration and its handling in LS, that definetly should be addressed in a time while.

nope. I don’t have a local settings. only thing I found is a default folder of ~/.vscode.

settings of VS Code only mentioned about “build command”. I don’t know what it’s doing when I press “Command s”.

For all my project I use locally npm installed purescript and spago
and .vscode/settings that look like this:

  "purescript.addNpmPath": true,
  "purescript.buildCommand": "npx spago build --purs-args --json-errors"

This makes LS to work ok with local versions. And if to run spago with npx spago it uses local purs too.

1 Like

I have to trace the problem next time I encounter this error. I guess it was probably triggered after I updated package-sets.

This is not very good if people have to deal with issues this way. There are still some problems with config handling when conflicting versions of purs installed locally and globally.


Are you sure about that? I don’t think you need npx. addNpmPath's docs states that it decides “whether to add the local npm bin directory to the PATH for purs IDE server and build command.” Also, I just tested this by removing my purescript and spago global installations and my editor worked just fine.

I mean running spago from the command line terminal in the project. If you run just spago it runs a globally installed one, that should use globally installed purs.

Well, we’re talking about an editor option here, so npx is not needed.

You mean "purescript.buildCommand": "npx spago build --purs-args --json-errors"? Without npx I run intro different issues, when I had globably installed purs 13, and local 14. It (spago) tried to use 13.

I never faced such issues, but maybe I just got lucky.

But this is obvious, that if you (or tooling) run just “spago” how should it know that it should locate the local purs in node_modules, spago itself has no such capabilities, afaic. Though it could work using paths supplied, but it didn’t for me, need to check and see the LS code more carefully.