Error building player because scripts had compiler errors

Every time i try to build my game. I get an error:

Exception: Error building Player because scripts had compiler errors UnityEditor.BuildPlayerWindow.BuildPlayerWithDefaultSettings (Boolean askForBuildLocation, BuildOptions forceOptions) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/BuildPlayerWindow.cs:341) UnityEditor.BuildPlayerWindow.GUIBuildButtons (Boolean enableBuildButton, Boolean enableBuildAndRunButton, Boolean canInstallInBuildFolder) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/BuildPlayerWindow.cs:949) UnityEditor.BuildPlayerWindow.ShowBuildTargetSettings () (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/BuildPlayerWindow.cs:923) UnityEditor.BuildPlayerWindow.OnGUI () (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/BuildPlayerWindow.cs:697) System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/GUI/DockArea.cs:213) UnityEditor.HostView.Invoke (System.String methodName) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/GUI/DockArea.cs:206) UnityEditor.HostView.OnGUI () (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/Mono/GUI/DockArea.cs:107)

I get this error on both Web player and PC And Mac Standalone.

Have you added any DLLs or editor scripts? Those are often the culprit. For example:

http://answers.unity3d.com/questions/22748/build-fails-in-unity-3-0

Old question, but I found a solution to the same/similar issue.

I have a .js file which uses the AnimationUtility, which is an Editor Class. The script had to be located in the folder Assets > Editor in order for the build to succeed.

Project played fine in the editor window when the .js was in my Assets > Script folder.

Errors in the console were a bit misleading, but the biggest hint was “BCE0005: Unkown identifier: ‘AnimationUtility’”. The other two errors made me think I jacked up the GUI or had a corrupt project. Luckily this was a quick fix to simply move the script into the correct folder.

Hopefully this will help someone else.

The culprit for me was that I made a change to one of the properties in the Facebook.Unity.dll.
In the FacebookSDK / Plugins folders, there is this file called Facebook.Unity.
When I clicked on it it brings up these options in the inspector. Well the only thing that was checked was the ‘Any Platform’ checkbox.

I checked the iOS option and unchecked ‘Any Platform’ options.
Well, I shouldn’t have done that. That’s when I got the “Error building player because scripts had compiler errors” error.

So I rechecked the ‘Any Platform’ option and unchecked the iOS option and everything built just fine.