James 2:21-26 is the second half of the “problem” passage where it appears that the Apostles James and Paul disagree about how we are justified. The key to resolving the apparent contradiction is context. James and Paul are addressing two different questions.
James and Paul appear to contradict each other because they use the same vocabulary: faith, works and justification. Plus they both appeal to Abraham. But they use the same language in very different contexts to address different problems and answer different questions.