Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

vite + react + typescript => getting an "failed to resolve import prop-types from path-here. Does this file exist error" #16574

Closed
7 tasks done
mrjayviper opened this issue May 2, 2024 · 0 comments

Comments

@mrjayviper
Copy link

Describe the bug

some info:

  • I'm new to typescript/react but I'm familiar with Javascript.
  • I'm just developing locally for now
  • I'm using npm run dev to start the local webserver
  • this is the full error

` [plugin:vite:import-analysis] Failed to resolve import "prop-types" from "src/components/MyComponent.tsx". Does the file exist?

    D:/projects/multipath-react-typescript/src/components/MyComponent.tsx:1:34
    15 |    window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
    16 |  }
    17 |  import PropTypes from "prop-types";
       |                         ^
    18 |  export default function MultiPathComponent(props) {
    19 |    return /* @__PURE__ */ jsxDEV(Fragment, { children: /* @__PURE__ */ jsxDEV("h1", { children: [`
  • these are the contents of MyComponent.tsx

` import PropTypes from 'prop-types'

    interface Props { name: string }

    export default function MyComponent(props: Props) {

        return (

            <>

                <h1>hello {props.name}</h1>

            </>

        )

    }        

    MyComponent.propTypes = { name: PropTypes.string.isRequired }`
  • the error disappears if I comment out the last line but I believe propTypes and Typescript serve different uses (at least from what I read in another SO discussion)
  • I have a plain JSX version of the code and I don't encounter any errors there when using "prop-types"
  • I compared vite.config.js for both TSX and JSX version of the code and they are the same.

Reproduction

https://github.com/mrjayviper/my-sample-react

Steps to reproduce

  • npm install
  • npm run dev

System Info

the sample command above causes an error on my laptopn

- windows11
- nodejs 20.12.2
- npm 10.5.0

Used Package Manager

npm

Logs

No response

Validations

@vitejs vitejs locked and limited conversation to collaborators May 2, 2024
@bluwy bluwy converted this issue into discussion #16575 May 2, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

1 participant