New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node_modules not copied to output folder when running dotnet publish #4062

Closed
henningst opened this Issue Aug 18, 2016 · 8 comments

Comments

Projects
None yet
6 participants
@henningst
Copy link

henningst commented Aug 18, 2016

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: 1e9d529

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

@henningst

This comment has been minimized.

Copy link

henningst commented Aug 18, 2016

Looks like this is a dupe of #3828

@henningst henningst closed this Aug 18, 2016

@avezenkov

This comment has been minimized.

Copy link

avezenkov commented May 5, 2017

This is not a duplicate of #3828. This is a different issue. node_modules isn't empty - npm install is run as pre- publish

@chinmayapradhan

This comment has been minimized.

Copy link

chinmayapradhan commented Jun 22, 2017

Any luck on this issue? I am still seeing that node_modules folder is not included as part of publish process.

@avezenkov

This comment has been minimized.

Copy link

avezenkov commented Jun 22, 2017

I suggest using a workaround - copy what is needed using xcopy or msbuild. Certainly don't use gulp js as it's slow as hell, pipes blabla... slow as hell. Webpack is great if you are looking for a build package manager.

@andymcintosh

This comment has been minimized.

Copy link

andymcintosh commented Jun 22, 2017

Following the comments on #3828 lead me to a solution for this issue as well. mkdir node_modules before calling published resulted in the node_modules directory, with all of its contents being published to the output folder

@dasMulli

This comment has been minimized.

Copy link
Contributor

dasMulli commented Jun 23, 2017

You could also remove the default node_modules exclude that the web-sdk adds by adding this to the csproj file:

  <PropertyGroup>
    <DefaultItemExcludes>$([System.String]::Copy($(DefaultItemExcludes)).Replace(';**\node_modules\**',''))</DefaultItemExcludes>
    <DefaultItemExcludes>$([System.String]::Copy($(DefaultItemExcludes)).Replace(';node_modules\**',''))</DefaultItemExcludes>
  </PropertyGroup>

However this will make building and publishing a bit slower since msbuild will scan the entire node_modules folder which may be slow.

@zelliott

This comment has been minimized.

Copy link

zelliott commented Sep 18, 2017

Is there a way to edit the DefaultItemExcludes so that only a handful of the modules in node_modules are included? For example, I need aspnet-webpack and webpack-hot-middleware for the dotnet JavascriptSpa services.

@dasMulli

This comment has been minimized.

Copy link
Contributor

dasMulli commented 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment