Replies: 1 comment
|
The import fails because the prop-types package isn't installed in this project — it's a standalone npm package, not something React or Vite ships. Vite's import-analysis tries to resolve import PropTypes from "prop-types" and can't find it in node_modules, hence "Failed to resolve import". That also explains your two observations: Commenting out MyComponent.propTypes = {…} makes the error disappear because that line is the only thing that actually uses PropTypes. Once it's gone, the now-unused import is dropped during transform, so Vite never has to resolve it. You have two options:
Option 2 is the idiomatic approach in a TypeScript + React codebase. |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
some info:
` [plugin:vite:import-analysis] Failed to resolve import "prop-types" from "src/components/MyComponent.tsx". Does the file exist?
` import PropTypes from 'prop-types'
Reproduction
https://github.com/mrjayviper/my-sample-react
Steps to reproduce
System Info
the sample command above causes an error on my laptopn - windows11 - nodejs 20.12.2 - npm 10.5.0Used Package Manager
npm
Logs
No response
Validations
All reactions