1

The SAFE Stack Documentation says to install npm (amongst other things) as a pre-requisite to build SAFE apps. But the link refers to https://www.npmjs.com where you have to search for packages. But which ones? What to install? There are thousands of packages there.

UPDATE: I have just noticed that the npm documentation says that npm comes bundled with node, & most third-party distributions, by default. So why does the SAFE Stack documentation show the link to npm? Is there any sense in it?

I have tried to install the npm package via NuGet. But whatever I do, running the SAFE standard template in VS ends with a NullReferenceException:

File helpers.fs

let runOrDefault args =
try
    match args with
    | [| target |] -> Target.runOrDefault target
    | _ -> Target.runOrDefault "Run" //NullReferenceException
    0
with e ->
    printfn "%A" e
    1

Entering dotnet run through a command prompt opens a console window containing these messages:

Starting target 'InstallClient'
.> "C:\Program Files\nodejs\npm.CMD" install (In: false, Out: false, Err: false)
npm ERR! code EBADENGINE
npm ERR! engine Unsupported engine
npm ERR! engine Not compatible with your version of node/npm: undefined
npm ERR! notsup Not compatible with your version of node/npm: undefined
npm ERR! notsup Required: {"node":"~16","npm":"~8"}
npm ERR! notsup Actual:   {"npm":"8.19.2","node":"v19.0.0"}

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\User\AppData\Local\npm-cache\_logs\2022-11-04T11_38_04_408Z-debug-0.log
Finished (Failed) 'InstallClient' in 00:00:02.0540071

UPDATE: In line with Tomáš Petříček's recommendation, I installed this version of node.js: Latest LTS Version: 18.12.0 (includes npm 8.19.2)

But again, NullReferenceException in VS, and the following error messages appear when using the command prompt:

Starting target 'InstallClient'
.> "C:\Program Files\nodejs\npm.CMD" install (In: false, Out: false, Err: false)
npm ERR! code EBADENGINE
npm ERR! engine Unsupported engine
npm ERR! engine Not compatible with your version of node/npm: undefined
npm ERR! notsup Not compatible with your version of node/npm: undefined
npm ERR! notsup Required: {"node":"~16","npm":"~8"}
npm ERR! notsup Actual:   {"npm":"8.19.2","node":"v18.12.0"}

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\User\AppData\Local\npm-cache\_logs\2022-11-04T13_19_03_959Z-debug-0.log
Finished (Failed) 'InstallClient' in 00:00:01.9942657

---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target          Duration
------          --------
Clean           00:00:00.5118885
InstallClient   00:00:01.9937254   (Process exit code '1' <> 0. Command Line: C:\Program Files\nodejs\npm.CMD install)
Run             00:00:00           (skipped)
Total:          00:00:02.6111670
Status:         Failure
---------------------------------------------------------------------
Fake.Core.BuildFailedException: Target 'InstallClient' failed.

2 Answers2

2

I think all you need to install is Node.js from the official download page There are two versions:

  • LTS (stable) - version 18 and
  • Current (development) - version 19

I previously installed "Current" and then run into various troubles (though different ones than you are reporting). You also seem to have 19 according to the log. I gave up with Current and reverted my setup to the LTS version. So perhaps uninstalling the Node version you have right now and installing Node LTS may help.

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
0

These adaptations made it possible to run the SAFE standard template on my PC in line with the Quick Start guidelines:

  1. Pre-requisites:
  • The .NET 6 SDK //OK

  • node.js (>= 8.0) //OK

  • npm //do not use this link

  • Azure CLI (optional - required for Azure deployments) //OK

  1. Continue with guidlines 1 to 6 in the "Create your first SAFE app" section. Use cmd for the dotnet run command.

  2. Look at the node and npm versions in this error message example:

    npm ERR! notsup Actual: {"npm":"8.19.2","node":"v18.12.0"}

    You may have different versions of npm and node, of course.

  3. In line with this article by Adam Johnson, do this:

    Open package.json in the root folder of the template and change the versions of npm and node accordingly, like this:

     "private":  true,                  
    
     "engines": {
    
         "node": "18.x",
    
         "npm": "8.x"
    
     }
    

    To suppress warnings, you may add *.npmrc file containing the text string engine-strict=true next to the package.json file.

This answer, however, does not solve the problem why there is a link to npm in the pre-requisites section.

The solution in this answer looks somewhat complicated so if you have got a better idea, it will be fine if you publish it.

UPDATE 08-Nov-2022

Instructions telling you how to run/debug a SAFE Stack app in Visual Studio are here. Then no more problems with NullReferenceExceptions.