-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
Cannot set properties of undefined
Type Error for React Moment package
#7376
Comments
This issue is simillar to #7053.
After prebundle, |
This comment was marked as off-topic.
This comment was marked as off-topic.
I digged down a bit more. vite/packages/vite/src/node/plugins/resolve.ts Lines 773 to 780 in fe4c1ed
So for a workaround, setting resolve.mainFields to [] will work.
I am not sure whether it is ok to change |
Can confirm that the above work around resolves the issue: Thanks @sapphi-red! |
Closing as #7582 should fix this issue too. |
@bluwy , the latest version of Vite ( I'm assuming a build with the fix just hasn't been released it. Thanks! |
Yes, it will be in 2.9.2, probably in a few days. We have some CI issues to check first. |
Sounds good. Thank you @patak-dev for the prompt reply! |
I am getting this error from a library
How do I fix this, the workaround is not working. I am using 3.0.3 version of vite |
The same thing happened to me and here #6675 (comment) I found the solution for my part, it works fine, you just have to modify the file |
It worked for me as well, thanks Jair :) |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Worked for me. Thanks!! |
I am not using CRA for a project and unfortunately the issue persists even with @trdxDeepu 's solution. |
I had some luck when importing import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
resolve: {
alias: [
{
// Allow moment.js to be used as an ESM module
find: /^moment$/,
replacement: path.resolve(__dirname, "./node_modules/moment/moment.js"),
},
],
},
}); |
Still problem after npm run build npm run dev working correctly |
TLDR: for people using moment, set Moment only exposes ESM files via the legacy |
Describe the bug
I'm migrating one of our projects at my company to Vite from CRA, and I see the following error in the console when I navigate to the locally hosted application in my browser:
See also the log file:
localhost-1647615535049.log
Needless to say, this wasn't an issue when we were using CRA.
I've tried a number of work arounds myself, but to no avail.
Happy to share if they're of interest.
Would love to find a fix for this as CRA is painfully slow for running a local development environment and building our project for production.
Thank you!
Reproduction
https://stackblitz.com/edit/vitejs-vite-vvkwaa
System Info
Used Package Manager
npm
Logs
N/A (no errors when running
vite
orvite build
)Validations
The text was updated successfully, but these errors were encountered: