Duplicate identifier LibraryManagedAttributes

This article introduces the solution to the Duplicate identifier LibraryManagedAttributes error, including the advantages, implementation details, and related resources that can help improve efficiency when dealing with this TypeScript compilation issue.

Dec 24, 2019 · 1 min read · 166 Words · -Views -Comments · Programming
TypeScript Node.js 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

Recently, when upgrading a frontend package, I encountered the following error. After analysis, I finally fixed it. Here’s my note on this issue.

Root Cause

Looking at the specific error message, there are two versions of React type definitions existing simultaneously.

@types/react versions in yarn.lock - note there are two

Solutions

TSC Configuration skipLibCheck Wrong Approach

If you add the skipLibCheck configuration to tsconfig.json and recompile with TSC, it actually works, but this approach is not recommended because you’re giving up some type safety. So don’t do this, even though it’s possible.

Package.json Current Approach

Add the following configuration:

"resolutions": {
    "@types/react": "~16.8.19"
  }

Re-run the yarn command, and you’ll find that the lock file now only has one version.

Other Methods

Besides the above solution, we can manually or use tools to remove duplicate package issues, though the lock file will inevitably need modification.

References

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover