question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack incompatibility when running a calendar with react native web. Seemingly simple solution.

See original GitHub issue

Description

I’m trying to run my simple one-page project which uses CalendarList in Expo’s react native web, but webpack gives an error & my project can’t run.

Source of Issue & Proposed Solution

I’ve figured out that the source of the issue seems to be that you can’t mix import & module.exports in the same file or otherwise webpack will not work. Stated here & very helpful info here. You guys mix them in the .../src/dateutils & .../src/day-state-manager files for example.

Mixing them seems like really bad practice anyway so might as well fix the mixing of CommonJS & ES Modules so that way webpack will play nice with your files!

For example, you can change module.exports = in your dateutils file to export default & that would fix the problem for that one file. Then you do the same for all the other files that have this.

Expected Behavior

Run expo r -c to run my project which uses CalendarList. Expected the project to start as normal.

Observed Behavior

Project didn’t run & showed an error page.

Error:

TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
Module.<anonymous>
node_modules/react-native-calendars/src/dateutils.js:145
  142 |   }
  143 | }
  144 | 
> 145 | module.exports = {
  146 |   weekDayNames,
  147 |   sameMonth,
  148 |   sameWeek,

Here’s a screenshot of the error: Screen Shot 2021-05-26 at 9 47 19 PM

Environment

Please run these commands in the project folder and fill in their results:

  • npm ls react-native-calendars: calendar-sample@ /Users/ja/code/react-native/scratch/calendar-sample └── react-native-calendars@1.1262.0
  • npm ls react-native: calendar-sample@ /Users/ja/code/react-native/scratch/calendar-sample ├─┬ react-native-safe-area-context@3.2.0 │ └── react-native@0.63.2 deduped └─┬ react-native@0.63.2 └─┬ @react-native-community/cli@4.14.0 └── react-native@0.63.2 deduped
  1. Phone/emulator/simulator & version: This was run using react native web 0.13.18.

Reproducible Demo

Make sure you’re using react-native-calendars version 1.1262.0. Install that exact version. An older version of 1.1260.0 & some other older versions didn’t seem to have this issue.

Then try to use this component for the web through react native web or through Expo (which uses react native web). They’ll use webpack & should give an error.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
pratheekhegdecommented, May 27, 2021

Facing the same issue. 😞

4reactions
foloinfocommented, Jun 2, 2021

I had a same issue and it seems like reverting to 1.1260.0 works.

However the recent version did not apply selectedDayTextColor correctly on the web, it was always black. So I ended up reverting way back to 1.403.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to compile on React Native Web - Stack Overflow
To fix it do the following: 1- Make sure to include the package folder in the babelLoader configuration in webpack.config.js as
Read more >
How to share a Node.js backend with a React web app and a ...
I use one server to host multiple apps, on digital ocean. I do it by running multiple nodejs apps, all running on different...
Read more >
Understanding (all) JavaScript module formats and tools
Webpack is a bundler for modules. It transpiles combined CommonJS module, AMD module, and ES module into a single harmony module pattern, ...
Read more >
react-calendar - npm
Prop name Description Default value onActiveStartDateChange n/a onClickDay Function called when the user clicks a day. n/a onClickDecade Function called when the user clicks a decade....
Read more >
Towards the definitive evaluation framework for cross-platform ...
It is easy to imagine that developing an app supposed to run on a smartphone as well ... (2017), Ionic, Progressive Web Apps,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found