question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"dotnet new" fails to install a new template with "node_modules" with "Error: Value cannot be null" message

See original GitHub issue

From @dance2die on April 4, 2018 1:36

Steps to reproduce

  1. Create a new dotnet new SPA project, react.
dance2die@LELOUCH c:\misc\sources\github
> dotnet new react -n ThisFails
The template "ASP.NET Core with React.js" was created successfully.

Processing post-creation actions...
...
Manual instructions: Run "npm install"
  1. Go to the newly created project.
dance2die@LELOUCH c:\misc\sources\github
> cd ThisFails
  1. Install NPM packages.
dance2die@LELOUCH c:\misc\sources\github\ThisFails
> npm install
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but npm-shrinkwrap.json was generated for lockfileVersion@0. I'll try to do my best with it!
...
added 546 packages in 136.886s
  1. Add a new template folder, .template.config and a new configuration file, template.json.
  2. Copy the following configuration to template.json file.
{
  "$schema": "http://json.schemastore.org/template",
  "author": "Sung Kim",
  "classifications": ["Web"],
  "name": "BadTemplate",
  "identity": "BadTemplate",
  "shortName": "badtemplate",
  "tags": {
    "language": "C#",
    "type": "project"
  },
  "sourceName": "BadTemplate",
  "preferNameDirectory": true
}
  1. Go up one directory.
dance2die@LELOUCH c:\misc\sources\github\ThisFails
> cd ..
  1. Install the template, ThisFails.
dance2die@LELOUCH c:\misc\sources\github
> dotnet new -i .\ThisFails
Error: Could not install ".\ThisFails".
Error: Value cannot be null.
Parameter name: key
...
Examples:
    dotnet new mvc --auth Individual
    dotnet new mstest
    dotnet new --help

Expected behavior

Go to the ThisFails folder and delete node_modules folder.

dance2die@LELOUCH c:\misc\sources\github
> cd ThisFails
dance2die@LELOUCH c:\misc\sources\github\ThisFails
> rmdir /S /Q node_modules

Go up one directory

dance2die@LELOUCH c:\misc\sources\github\ThisFails
> cd ..

Installing works without an error.

dance2die@LELOUCH c:\misc\sources\github
> dotnet new -i .\ThisFails
Templates                                         Short Name       Language          Tags
--------------------------------------------------------------------------------------------------------
...
BadTemplate                                       badtemplate      [C#]              Web
...
Examples:
    dotnet new mvc --auth Individual
    dotnet new console
    dotnet new --help

Actual behavior

Fails with following error message.

dance2die@LELOUCH c:\misc\sources\github                                                                
> dotnet new -i .\ThisFails                                                                             
Error: Could not install ".\ThisFails".                                                                 
Error: Value cannot be null.                                                                            
Parameter name: key                                                                                     
Templates                                         Short Name       Language          Tags               
--------------------------------------------------------------------------------------------------------
Console Application                               console          [C#], F#, VB      Common/Console     
Class library                                     classlib         [C#], F#, VB      Common/Library     
Unit Test Project                                 mstest           [C#], F#, VB      Test/MSTest        
xUnit Test Project                                xunit            [C#], F#, VB      Test/xUnit         
BadTemplate                                       badtemplate      [C#]              Web                
ASP.NET Core Empty                                web              [C#], F#          Web/Empty          
ASP.NET Core Web App (Model-View-Controller)      mvc              [C#], F#          Web/MVC            
ASP.NET Core Web App                              razor            [C#]              Web/MVC/Razor Pages
ASP.NET Core with Angular                         angular          [C#]              Web/MVC/SPA        
ASP.NET Core with React.js                        react            [C#]              Web/MVC/SPA        
ASP.NET Core with React.js and Redux              reactredux       [C#]              Web/MVC/SPA        
ASP.NET Core Web API                              webapi           [C#], F#          Web/WebAPI         
global.json file                                  globaljson                         Config             
Nuget Config                                      nugetconfig                        Config             
Web Config                                        webconfig                          Config             
Solution File                                     sln                                Solution           
Razor Page                                        page                               Web/ASP.NET        
MVC ViewImports                                   viewimports                        Web/ASP.NET        
MVC ViewStart                                     viewstart                          Web/ASP.NET        
                                                                                                        
                                                                                                        
Examples:                                                                                               
    dotnet new mvc --auth Individual                                                                    
    dotnet new mstest                                                                                   
    dotnet new --help                                                                                   

Environment data

dance2die@LELOUCH c:\misc\sources\github\ThisFails   
> dotnet --info                                      
.NET Command Line Tools (2.0.2)                      
                                                     
Product Information:                                 
 Version:            2.0.2                           
 Commit SHA-1 hash:  a04b4bf512                      
                                                     
Runtime Environment:                                 
 OS Name:     Windows                                
 OS Version:  10.0.16299                             
 OS Platform: Windows                                
 RID:         win10-x64                              
 Base Path:   C:\Program Files\dotnet\sdk\2.0.2\     
                                                     
Microsoft .NET Core Shared Framework Host            
                                                     
  Version  : 2.0.0                                   
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

Copied from original issue: dotnet/cli#8989

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mlorbetskecommented, Apr 11, 2018

The CLI after 2.1.300-preview2 should contain the update (2.1.3xx)

Get Outlook for iOShttps://aka.ms/o0ukef


From: Sung Kim notifications@github.com Sent: Tuesday, April 10, 2018 7:39:06 PM To: dotnet/templating Cc: Mike Lorbetske; Mention Subject: Re: [dotnet/templating] “dotnet new” fails to install a new template with “node_modules” with “Error: Value cannot be null” message (#1498)

Thank you @mlorbetskehttps://github.com/mlorbetske . Would the next release of dotnet CLI reflect the update?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/dotnet/templating/issues/1498#issuecomment-380308102, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABWXUeamL6BMbNOHtvBjs1BWAkadlaQyks5tnWzKgaJpZM4TGDa4.

1reaction
mlorbetskecommented, Apr 4, 2018

TL;DR - the particular node modules that have been added to the project contain a template.json file

In newer CLIs, the crash issue has been fixed & some diagnostics have been added (you can get a better feel for what’s going wrong by specifying the --trace:authoring flag when installing the package). Unfortunately, it doesn’t make this particular case much clearer, we end up inferring enough of the settings to make it through the basic validation that if the template could be installed it could run (though it probably wouldn’t do anything of interest). Things fall down though when it finally tries to register it - the “identity” property is missing from the file, causing it to null reference out when adding it to the in-memory cache before writing it to disk.

There’s another item (#1492) that also touches on this topic. I’m preparing a PR now to:

  • Reject things that don’t include some of the “required fields” so that it never makes it to the registration
  • Enhancing the authoring information available at install time to call out specifically what’s missing
Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet new install issue - Error: Value cannot be null
According to Mike Lorbetske, the error occurs when one of the node_modules folders contain a template.json file. TL;DR - the particular node ......
Read more >
Using dotnet build project occurred value cannot be null error
The error message you're seeing is related to NuGet, which is used for package management in .NET projects. The error "Value cannot be...
Read more >
dotnet new install - .NET CLI
The dotnet new install command installs a template package.
Read more >
Troubleshooting JSS Next.js apps
Error : Valid value for rootItemId not provided and failed to auto-resolve app root item. This error occurs because the Next.js app and...
Read more >
Creating new Node.js Express app results bunch of warnings
I just created a new basic Node.js Express web app from new project menu. ... Second message: [Window Title] Path Too Long Warning...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found