I've looked at the resolutions for similar problems here, but they all appear to deal with pre-existing modules. This is happening to a React Component I wrote myself, and I'm not sure how to get around it.
import React from 'react';
import { useForm } from "react-hook-form"
import axios from 'axios'
export default FileUploadForm = () => {
const { register, handleSubmit, /* errors */ } = useForm()
const onSubmit = (data: string | Blob) => {
console.log(data)
const formData = new FormData();
formData.append("image", data)
axios.post('http://localhost:3000', formData)
}
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input required ref={register} type="file" name="image" />
<button>Submit</button>
</form>
)
}
Typescript is identifying a problem with the declaration of FileUploadForm
on line 5, giving me the error I specified in the title. Although, I'm uncertain if it's to do with Typescript. I'm also getting the following compiler error:
My project structure is as follows:
My package.json is as follows:
{
"name": "file-uploader-frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/axios": "^0.14.0",
"axios": "^0.21.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-hook-form": "^7.13.0",
"react-scripts": "4.0.3",
"typescript": "^4.3.5",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/node": "^16.7.2"
}
}
Currently, this is the state of the compiled FileUploadForm.jsx. The component is being imported into App.js as a named import:
"use strict";
exports.__esModule = true;
exports.FileUploadForm = void 0;
var react_1 = require("react");
var react_hook_form_1 = require("react-hook-form");
var axios_1 = require("axios");
var FileUploadForm = function () {
var _a = react_hook_form_1.useForm(), register = _a.register, handleSubmit = _a.handleSubmit;
var onSubmit = function (data) {
console.log(data);
var formData = new FormData();
formData.append("image", data);
axios_1["default"].post('http://localhost:3000', formData);
};
return (<form onSubmit={handleSubmit(onSubmit)}>
<input required ref={register} type="file" name="image"/>
<button>Submit</button>
</form>);
};
exports.FileUploadForm = FileUploadForm;
I'm sure there are several other problems with my code, but I can't even begin to explore them if I can't get past this problem so I can get the page to render. I've attempted this as both a named export and a default export. The result is the same. I'm at a loss for what to do next. Any help would be appreciated.