Skip to content
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

TypeError: Cannot set properties of undefined when using react-live-clock with React and Vite #319

Closed
kavindunilshan opened this issue Jun 8, 2024 · 6 comments

Comments

@kavindunilshan
Copy link

Description:
I encountered an issue when using react-live-clock in my React project that is built with Vite. When I import and use the Clock component from react-live-clock, it causes a TypeError.

This issue is same as what has been described in this Stack Overflow question: Problem using react-live-clock and react-moment.

Steps to Reproduce:

  1. Install dependencies:
    npm install --save react react-live-clock

2.Import and use the Clock component in a React component.

import React from 'react';
import Clock from 'react-live-clock';

const MyComponent = () => (
  <div>
    <Clock format={'HH:mm:ss'} ticking={true} timezone={'US/Pacific'} />
  </div>
);

export default MyComponent;
  1. Run the project using vite
    npm run dev

Environment:

React version: 18.2.0
Vite version: 5.2.0
react-live-clock version: 6.1.22 (also checked with 6.1.16 but both didn't work)

The error seems to be related to the internal implementation of the react-live-clock component or its interaction with the Vite build process. Any insights or workarounds for this issue would be greatly appreciated.

@thesilhouettes
Copy link

I am not the author of this repository, but could you try adding the resolve field in vite.config.js?

import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    mainFields: [],
  },
});

I hope this solves your problem.

@anthony0030
Copy link
Collaborator

Hi @kavindunilshan, Thanks for the feedback. I don't know how VITE works.
Here are some similar problems to yours:
#150
#220
#275
Maybe you can use a solution from there or reach out to the other developers to give you a hand.

@anthony0030
Copy link
Collaborator

Also, Thanks @thesilhouettes for the response. I can't verify if it works, but still tanks :D

@kavindunilshan
Copy link
Author

kavindunilshan commented Jun 13, 2024

@thesilhouettes Thank you!, Adding the resolve field in vite.config.js solved my issue perfectly. Much appreciated!

@kavindunilshan
Copy link
Author

@anthony0030 Thanks! I really appreciate your help!

@anthony0030
Copy link
Collaborator

Happy to help @kavindunilshan.
@thesilhouettes will the config modification be needed in all cases?
Is there a change I can make to the project to make it compatible without the mod? Would this mod be good to add in the documentation?

Thanks again for the solution @thesilhouettes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants