-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
Help on how to import DatePickerElement #275
Comments
hi @larsinho81 I am not sure what is the issue on your tsconfig. Can you try out folliwing patterns recommended here: |
Hi @dohomi, I had a look at the comment, the only hint I can see is changing the module resolution to node16, which currently is not a direct option for our project. I have the assumption the this kind of module resolution may be a rather new feature which requires a newer module resolution version (node 16 or nodenext). But I am not sure. |
I use |
Yes, I will spin up a codepen when I have some time and explore a little more. Thanks! |
I have the same issue if I change "module": "NodeNext",
"moduleResolution": "NodeNext", it works, but it is not compatible with nextjs. For example then you will not be able to dynamically load components
import dynamic from 'next/dynamic'
const MyComponent = dynamic(() =>
import('components/MyComponent').then((mod) => mod.MyComponent)
) Possible solution: import it directly, but this will not trigger auto import import { DatePickerElement } from 'react-hook-form-mui/dist/date-pickers' |
I tried following @FDiskas solution of importing it directly but got the following error from Vite:
I also can't change my moduleResolution config, so I'm unable to use DatePickerElement |
You can't just import it the normal way and live without the intellisense? For me, with moduleResolution set to "Node", and using vite, the component works if I import it like
The ts-expect-error is so this isn't showing up as an error. Because, it's not an error, it builds and bundles fine in our solution. We just lose the intellisense and typings for the props. Annoying, but not as annoying as trying to "fix" things to use Node16/NodeNext moduleResolution |
I'm using |
Thanks @dantheother, so works for me as well, for now. |
If anybody could elaborate which setting of tsup is needed to prevent this error from happening I would appreciate. I am happy to review a PR to fix it once and for all, weirdly I've never seen it in my own environment |
Everything is fine with your package, this is just us with old setups and legacy projects. https://nodejs.org/api/packages.html#package-entry-points |
As a quick fix for the developers who have issues:
In case you need to stick to
Patch content
diff --git a/node_modules/react-hook-form-mui/package.json b/node_modules/react-hook-form-mui/package.json
index 6018b11..b52a7fb 100644
--- a/node_modules/react-hook-form-mui/package.json
+++ b/node_modules/react-hook-form-mui/package.json
@@ -3,33 +3,26 @@
"license": "MIT",
"repository": "https://github.com/dohomi/react-hook-form-mui",
"homepage": "https://react-hook-form-material-ui.vercel.app",
- "keywords": ["react", "mui", "material-ui", "react-hook-form"],
- "workspaces": ["apps/*", "packages/*"],
+ "keywords": [
+ "react",
+ "mui",
+ "material-ui",
+ "react-hook-form"
+ ],
+ "workspaces": [
+ "apps/*",
+ "packages/*"
+ ],
"name": "react-hook-form-mui",
"author": "Dominic Garms",
"source": "src/index.ts",
"main": "dist/index.js",
"module": "dist/esm/index.js",
"typings": "dist/index.d.ts",
- "files": ["dist/**", "src/**"],
- "exports": {
- "./package.json": "./package.json",
- ".": {
- "types": "./dist/index.d.ts",
- "import": "./dist/esm/index.js",
- "require": "./dist/index.js"
- },
- "./date-fns": {
- "types": "./dist/date-fns.d.ts",
- "import": "./dist/esm/date-fns.js",
- "require": "./dist/date-fns.js"
- },
- "./date-pickers": {
- "types": "./dist/date-pickers.d.ts",
- "import": "./dist/esm/date-pickers.js",
- "require": "./dist/date-pickers.js"
- }
- },
+ "files": [
+ "dist/**",
+ "src/**"
+ ],
"engines": {
"node": ">=14"
}, |
Latest nextjs - I managed to import the date picker and not loose the lazy loading components by specifying compile options like so "module": "esnext",
"moduleResolution": "bundler", but I'm not sure why and what it does |
in addition, i need to import the component like this. i get no autocomplete intellisense import { DatePickerElement } from "react-hook-form-mui/date-pickers"; |
Hey,
thank you for providing this package!
I need guidance on how to import the DatePickerElement.
I try to import the component as
import { DatePickerElement, DatePickerElementProps } from 'react-hook-form-mui/date-pickers';
But get the following typescript error:
Cannot find module 'react-hook-form-mui/date-pickers' or its corresponding type declarations. There are types at '/Users/lars.reith/Repositories/PO2/POWebApp/node_modules/react-hook-form-mui/dist/date-pickers.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.ts(2307)
The problem can be resolved changing the module resolution strategy to node16 in tsconfig, but this is currently not an option because it brings other resolving issues to the project. We are currently using node/esnext as the module resolution strategy. And typescript 4.6.4. Should it possible to import the date / time pickers properly with this setup?
The text was updated successfully, but these errors were encountered: