error NU1004: The package reference Newtonsoft.Json version has changed from [13.0.3, ) to [13.0.4, ).The packages lock file is inconsistent with the project dependencies so restore can't be run in locked mode. ... means the project file and the committed packages.lock.json disagree, and --locked-mode forbids restore from changing the lock file. If the change in the project is the one you want, run a normal dotnet restore once to rewrite the lock file and commit both files together.

The first sentence of the message names the exact difference, here one version. In the test a normal restore wrote 13.0.4 into the lock file and the next locked-mode restore passed. Lock1 is this test's own project, with a nuget.config of its own. The commands on this page ran in cmd.

The error

dotnet restore --locked-mode
  Determining projects to restore...
C:\...\cfg\Lock1\Lock1.csproj : error NU1004: The package reference Newtonsoft.Json version has changed from [13.0.3, ) to [13.0.4, ).The packages lock file is inconsistent with the project dependencies so restore can't be run in locked mode. Disable the RestoreLockedMode MSBuild property or pass an explicit --force-evaluate option to run restore to update the lock file.
  Failed to restore C:\...\cfg\Lock1\Lock1.csproj (in 49 ms).
exit=1

The paths are shortened. The missing space after [13.0.4, ). is in the message as printed.

Why it happens

The project opts in to a lock file, and the first restore wrote one:

...
    <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
  </ItemGroup>
...
dotnet restore
  Determining projects to restore...
  Restored C:\...\cfg\Lock1\Lock1.csproj (in 42 ms).
exit=0
findstr /C:"resolved" packages.lock.json
        "resolved": "13.0.3",
exit=0

Then the version in the project file was changed to 13.0.4, the way an upgrade lands in a pull request, and the restore ran with --locked-mode, as a build that must not change the lock file would. The project now asked for a version range the lock file did not record, the message named both ranges, and the restore stopped with exit code 1 instead of updating the file. That is the switch doing its job: a version changed without the lock file changing with it.

The fix

dotnet restore
  Determining projects to restore...
  Restored C:\...\cfg\Lock1\Lock1.csproj (in 87 ms).
exit=0
findstr /C:"resolved" /C:"requested" packages.lock.json
        "requested": "[13.0.4, )",
        "resolved": "13.0.4",
exit=0
dotnet restore --locked-mode
  Determining projects to restore...
  Restored C:\...\cfg\Lock1\Lock1.csproj (in 69 ms).
exit=0

Run the normal restore on your own machine, on purpose, after a change you mean to make, and commit packages.lock.json with the project file. Keep the locked restore where the lock file must not change: in this test it was the step that noticed a version change the lock file had not recorded. The message also offers --force-evaluate; that option was not run here.

How it was reproduced

A console project from dotnet new console -f net10.0 with SDK 11.0.100 on Windows 11, RestorePackagesWithLockFile set, Newtonsoft.Json 13.0.3, and a nuget.config in the project folder with only nuget.org. One normal restore wrote the lock file, the reference was changed to 13.0.4, and dotnet restore --locked-mode failed. A normal restore and a second locked restore followed. Both versions were already in the local package folder. Every command shown without a PS> marker ran in cmd: a PowerShell script passed it as cmd /c ... 2>&1 and printed the exit= line after it.

Frequently asked

How do I fix NU1004 the packages lock file is inconsistent?
If the change in the project file is intended, run dotnet restore without --locked-mode once to rewrite packages.lock.json, then commit both files. In this test the next locked-mode restore passed.
Why does dotnet restore --locked-mode fail after I upgrade a package?
Locked mode refuses to change packages.lock.json. The upgraded version in the project file was not in the lock file, so NU1004 named the old and new version ranges and the restore failed with exit code 1.
What did dotnet restore --locked-mode do before and after the lock file was updated?
In this test it failed with NU1004 and exit code 1 while packages.lock.json still said 13.0.3, and restored with exit code 0 after a normal restore had written 13.0.4 into the lock file.

More decoded errors in the Fixes category. A vulnerable version found during restore is a different warning: NU1903.