dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.7k stars 1.06k forks source link

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

Closed dance2die closed 4 years ago

dance2die commented 6 years ago

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"

2. Go to the newly created project.
```bash
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
  2. Add a new template folder, .template.config and a new configuration file, template.json.
  3. 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
    }
  4. Go up one directory.
    dance2die@LELOUCH c:\misc\sources\github\ThisFails
    > cd ..
  5. 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
livarcocc commented 6 years ago

This issue was moved to dotnet/templating#1498