Visual Studio Code "Could not find module Daml.Script" when multiple Daml projects open

Hi, I created a new directory, and from there issued the following commands:

daml new test1
daml new test2
daml studio

When Visual Studio starts if I navigate to either “Main.daml” file I see the red wiggly line under “import Daml.Script” and the error is “Could not find module ‘Daml.Script’”. The option to run the script in Visual Studio is not there.

If I run “daml studio” from directory “test1” or “test2” then there is no error and the script works fine.

This used to work ok prior to Daml 2.0, and is useful functionality when composing applications from multiple projects. Would be good to know if this is reproducible or if it is a problem with my environment? Thanks!

1 Like

I can reproduce this locally by following the steps you took. This is an instance of a known issue: Package database is not initialized if IDE is started in a parent directory · Issue #5455 · digital-asset/daml · GitHub

If I run daml build manually in each of the subdirectories, and then reopen daml studio in the parent directory, the red squiggly line goes away and the Script Results shows up and starts working as normal.

This fix works because daml build caused the package-db to be created, so damlc can find the daml-script dependency. Ideally this would be done automatically, but right now you have to do it manually each time your dependencies change (or when you create the project the first time).

We haven’t changed this behavior in recent times, so I would say this isn’t a regression in Daml 2.0. It seems likely to me that in the cases it worked for you in the past, you had already run daml build from the subdirectories at least once.

2 Likes

Thank you @Sofia_Faro for not only giving me a solution but also explaining why it behaves as it does. It is very likely that in the past I had done a build so although I saw the issue for the first time when starting a new set of projects on Daml 2.0 your explanation makes sense.

2 Likes