-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Error] Incorrect Import of PropTypes Causes Compilation Error #43700
Comments
Nitpick: If anyone encounters this issue, here is a quick fix for Unix systems using Yarn post-install:
Smth like this into
|
And to add my 2 cents, given that we’re facing this issue as the optimal fix appears to involve the Unix Here's a sample Bash script for deploying a React application that uses Material UI:
|
Switched from default imports to wildcard imports for PropTypes across multiple files. This change ensures consistency in PropTypes usage and can help with tree-shaking during the build process. Bug Report: mui#43700
I have verified that each package includes Here is the Pull Request addressing this fix: #43701 Please review it and let me know if there are any additional contributions or changes needed. |
I changed those imports in #23116, maybe it was wrong 🤔 |
@Janpot I've tailored the solution to directly address the core issue with the We can either keep this #43701 PR open for future reference or close it, depending on your preference. However, we should consider enhancing a codebase with a new PR by incorporating utilities to enable |
@oliviertassinari The issue with |
I think you were correct. I believe |
@Janpot Yeah agree, the problem is not with Material UI. In https://unpkg.com/browse/[email protected]/index.js, I see: const propTypes1 = require('prop-types');
import propTypes2 from 'prop-types';
import * as propTypes3 from 'prop-types';
propTypes1. // valid
propTypes2. // valid
propTypes3.default. // valid let's fix |
@Janpot @oliviertassinari I might be mistaken, but it appears that we should refer to the |
@oliviertassinari It's impressive how smoothly the previous decision was altered by #43700 (comment). Just a quick observation: the updated PR description still seems incorrect after update, as it references a |
@morozow We appreciate your willingness to contribute, but to reduce the risk of contributions being rejected, it would be best to wait until we've agreed on the appropriate solution. To be fully honest, I still don't understand what the exact problem is. At this point, the best thing you could do is to share a real reproduction (e.g. a codesandbox, or a github repository) that clearly demonstrates what you're trying to do and the error you're running into so that we can take a look. These imports have been there in this form since 2020, without any issues, I hope you understand that we're not going to make hasty changes to to them, especially when it's demonstrated they will be harmful in the future. It's clear that there is a mismatch between what the |
@Janpot I've set up a fresh repository at https://github.com/morozow/material-ui-tsc-fix.
Consequently, I encounter an issues documented at #43700 & #43685 |
Assuming a bundler will be consuming your library, you should be able to set |
@morozow I'm glad it works for you. Thank you for improving the docs. Is this issue sufficiently addressed for you so that we can close this ticket and the related ones?
We will have to revise our imports as part of #43264. I'm going to improve/fix the node-esm runtime tests before we touch those imports. |
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Note We value your feedback @morozow! How was your experience with our support team? |
Steps to reproduce
Link to live example: local dev as there's no TS completion to build live phase
Steps:
import PropTypes from 'prop-types';
.Current behavior
When using Material UI with TypeScript, I encountered a compilation error due to the incorrect use of
import PropTypes from 'prop-types';
in the codebase.Typescript Compiler error:
Current example of Material UI implementation:
material-ui/packages/mui-utils/src/chainPropTypes/chainPropTypes.ts
Line 1 in bb620d8
Since the
prop-types
library does not have a default export, this import statement is incorrect and should instead use named imports to align with ES6 module standards.https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/prop-types/index.d.ts
Solution: apply
import * as PropTypes from 'prop-types';
Expected behavior
The project should compile without errors.
Context
Replace all occurrences of
import PropTypes from 'prop-types';
withimport * as PropTypes from 'prop-types';
in the entire Material UI codebase.Additional Context
Your environment
npx @mui/envinfo
Search keywords: error, types, d.ts
The text was updated successfully, but these errors were encountered: