1

I suddenly got this error when building/debugging my Node project with Node Tools for Visual Studio (v1.1, not RC anymore). I was using Visual Studio Community Edition 2015 . I use Typescript, and also have the currently latest version of Typescript, e.g. v1.7.6.

Error:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Node.js Tools\Microsoft.NodejsTools.targets(119,5): error MSB4018: The "AssignTargetPath" task failed unexpectedly.
System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
at Microsoft.Build.Tasks.AssignTargetPath.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
Done building project "BuyCo.njsproj" -- FAILED.

Build FAILED.

When checking the interwebs the problems seems related to the MAXPATH issue with Node/npm. http://visual2073.rssing.com/chan-25873606/all_p116.html https://nodejstools.codeplex.com/workitem/759 https://nodejstools.codeplex.com/workitem/1340

Bart
  • 5,065
  • 1
  • 35
  • 43

2 Answers2

3

Took me sometime to find out, but a friend suggested to migrate from npm 2 to 3. . Below some details so others don't have to go through those terrible non-Stackoverflow fora's and such:).

The issue WAS related to the Windows MaxPath. In the end I managed to fix this by

  • upgrading from npm 2 to npm 3. For Windows user check here.
  • and then of course deleting all npm packages in my project rm -r node_modules
  • and then reinstalling them (npm install).

In npm3 they managed to have flatter folder structures. Though a drawback of it might be that the npm team has indicated it's still in beta, and that for real stability and migration you'll have to wait until npm4. I don't know enough about specifics. Anyhow npm3 worked for me.

As you might see I was working in git bash. Somehow the version pf npm in git bash was still on v2, while a normal command promt (e.g cmd) I already had v3. In bash you can also confirm you are indeed experiencing an issue due to MAXPATH with this command:

(find | awk '{ print length(), NR, $0 | "sort -rn" }' | less)

You are dropped in (less) editor. Check the first column/number, lines are ordered by lenght so just check the first line. Length should be below 260. Exit the editor with :q :). Note you should add base path lenght yourself, as the lenght within the current folder is indicated. Perhaps a bash wizard can provide a better command.

Bart
  • 5,065
  • 1
  • 35
  • 43
1

I keep getting the same issue in VS 2019 but then if I close and re-open it, the issue goes away for a while and I am able to build my project but then after a while it returns and I must close and re-open again. If you are getting the issue, could just be VS being temperamental. Might be worth restarting the program before trying anything more drastic.

Robin Wilson
  • 308
  • 2
  • 11