简体   繁体   中英

Aurelia bundle in Visual Studio 2015 Community

I have a postinstall rule set in package.json as follows:

"postinstall": "aurelia bundle --force"

If I run npm install from the cmd in the project folder, no error are displayed but when the project loads in Visual Studio 2015 Community, it show the following error in the Output window (but outputs the bundled file):

---> (Inner Exception #0) Microsoft.NodejsTools.Npm.PackageJsonException: Error reading package.json at '...\node_modules\aurelia-cli\node_modules\npm\node_modules\graceful-fs\package.json': Error reading package.json. The file may be parseable JSON but may contain objects with duplicate properties.

The following error occurred:

Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject. ---> Microsoft.NodejsTools.Npm.PackageJsonException: Error reading package.json. The file may be parseable JSON but may contain objects with duplicate properties.

The following error occurred:

Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject. ---> System.ArgumentException: Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.
   at Newtonsoft.Json.Linq.JObject.ValidateToken(JToken o, JToken existing)
   at Newtonsoft.Json.Linq.JContainer.InsertItem(Int32 index, JToken item, Boolean skipParentCheck)
   at Newtonsoft.Json.Linq.JObject.InsertItem(Int32 index, JToken item, Boolean skipParentCheck)
   at Newtonsoft.Json.Linq.JContainer.AddInternal(Int32 index, Object content, Boolean skipParentCheck)
   at Newtonsoft.Json.Linq.JContainer.Add(Object content)
   at Newtonsoft.Json.Linq.JTokenWriter.AddValue(JValue value, JsonToken token)
   at Newtonsoft.Json.Linq.JTokenWriter.WriteNull()
   at Newtonsoft.Json.JsonWriter.AutoCompleteClose(JsonContainerType type)
   at Newtonsoft.Json.JsonWriter.WriteEndObject()
   at Newtonsoft.Json.JsonWriter.WriteEnd(JsonContainerType type)
   at Newtonsoft.Json.JsonWriter.WriteEnd()
   at Newtonsoft.Json.JsonWriter.AutoCompleteAll()
   at Newtonsoft.Json.Linq.JTokenWriter.Close()
   at Newtonsoft.Json.JsonWriter.System.IDisposable.Dispose()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateJObject(JsonReader reader)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Microsoft.NodejsTools.Npm.ReaderPackageJsonSource..ctor(TextReader reader)
   --- End of inner exception stack trace ---
   at Microsoft.NodejsTools.Npm.ReaderPackageJsonSource..ctor(TextReader reader)
   at Microsoft.NodejsTools.Npm.FilePackageJsonSource..ctor(String fullPathToFile)
   --- End of inner exception stack trace ---
   at Microsoft.NodejsTools.Npm.FilePackageJsonSource.WrapExceptionAndRethrow(String fullPathToFile, Exception ex)
   at Microsoft.NodejsTools.Npm.FilePackageJsonSource..ctor(String fullPathToFile)
   at Microsoft.NodejsTools.Npm.DirectoryPackageJsonSource..ctor(String fullDirectoryPath)
   at Microsoft.NodejsTools.Npm.SPI.RootPackage..ctor(String fullPathToRootDirectory, Boolean showMissingDevOptionalSubPackages)
   at Microsoft.NodejsTools.Npm.SPI.NodeModules..ctor(IRootPackage parent, Boolean showMissingDevOptionalSubPackages)
   at Microsoft.NodejsTools.Npm.SPI.RootPackage..ctor(String fullPathToRootDirectory, Boolean showMissingDevOptionalSubPackages)
   at Microsoft.NodejsTools.Npm.SPI.NodeModules..ctor(IRootPackage parent, Boolean showMissingDevOptionalSubPackages)
   at Microsoft.NodejsTools.Npm.SPI.RootPackage..ctor(String fullPathToRootDirectory, Boolean showMissingDevOptionalSubPackages)
   at Microsoft.NodejsTools.Npm.SPI.NodeModules..ctor(IRootPackage parent, Boolean showMissingDevOptionalSubPackages)
   at Microsoft.NodejsTools.Npm.SPI.RootPackage..ctor(String fullPathToRootDirectory, Boolean showMissingDevOptionalSubPackages)
   at Microsoft.NodejsTools.Npm.SPI.NpmController.<RefreshAsync>d__1.MoveNext()<---

So does running npm install automatically from visual studio have any impact on the actual bundling of the scripts in a sense that it skips some modules when running automatically?

Visual Studio 2015 uses very old version of Node and npm. I had the similar issue with Tools for Apache Cordova apps.

You can make vs use the same Node and npm as cmd by changing some files including node.exe under C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Extensions\\Microsoft\\Web Tools\\External

Look for this article http://jameschambers.com/2015/09/upgrading-npm-in-visual-studio-2015/

In addition it looks like vs does not work with the latest 5.0.0 Node. Replacing with 4.2.2 one solves.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM