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.

node_modules not copied to output folder when running dotnet publish

See original GitHub issue

Steps to reproduce

  • Create a new ASP.NET Core Web App
  • Add a package.json file and specify at least one dependency
  • Add “npm install” in the scripts/prepublish section of project.json
  • Add “node_modules” in the publishOptions/include section of project.json
  • Run dotnet publish
  • See that node_modules is not included in the output

I’ve created a GitHub repo with a project showing this.

https://github.com/henningst/NodeModulePublishRepro

  • Clone the repo above
  • Run dotnet publish without opening it in Visual Studio first (because VS is automatically installing npm packages).

Expected behavior

node_modules should be copied to the output directory when running dotnet publish because:

  • npm install runs using the prepublish hook
  • node_modules is specified to be included

It should be possible to include the node_modules directory or any other file or directory in the publish output, even if these files or directories does not exist before running scripts using the prepublish hook.

Actual behavior

When running dotnet publish on a webapp with dependencies on node packages, the node_modules directory is not copied to the output directory even if npm install is run with the prepublish hook and node_modules is specified to be included.

It works if the node_modules directory exists before running dotnet publish, but when you run dotnet publish for the first time, node_modules will not exist before npm install is run via the prepublish hook.

Try running dotnet publish a second time, and you will see that node_modules is copied.

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview2-003121)

Product Information: Version: 1.0.0-preview2-003121 Commit SHA-1 hash: 1e9d529bc5

Runtime Environment: OS Name: Windows OS Version: 10.0.10586 OS Platform: Windows RID: win10-x64

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
dasMullicommented, Sep 18, 2017

@zelliott haven’t looked at it in detail but I guess these packages will pull in a lot of dependencies and tracing them all down would be hard…

Any folder or file that is not yet part of the project can still be imported manually (using Include="…" instead of Update="…"):

<ItemGroup>
  <Content Include="node_modules\foo\**" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
2reactions
henningstcommented, Aug 18, 2016

Looks like this is a dupe of https://github.com/dotnet/cli/issues/3828

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Folder not being copied to Output directory
I try to create blank .net core 3.1 project and when I click on publish I get the publish folder in bin\Release\netcoreapp3.1.
Read more >
Excluding the node_modules folder when publishing ASP ...
I'm starting off with an out of the box, new ASP.NET MVC application. If you're using ASP.NET Web Forms then the process should...
Read more >
dotnet publish command - .NET CLI
dotnet publish - Publishes the application and its dependencies to a folder for deployment to a hosting system. Synopsis .NET CLI Copy.
Read more >
Keeping Content Out of the Publish Folder for WebDeploy
I've run into issues with keeping files from publishing with WebDeploy on numerous occasions. When working with large projects it's not ...
Read more >
CopyFiles@2 - Copy files v2 task
Copy files v2 # Copy files from a source folder to a target folder using patterns matching file paths (not folder paths).
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