timofeysie / dot-one

A social network platform in vanilla React
1 stars 0 forks source link

rich text content build failure #9

Closed timofeysie closed 8 months ago

timofeysie commented 8 months ago

When deploying versions 0.1.3 to Heroku, this is the failed log:

-----> Installing dependencies
       Installing node modules
       npm ERR! code ERESOLVE
       npm ERR! ERESOLVE could not resolve
       npm ERR! 
       npm ERR! While resolving: react-html-parser@2.0.2
       npm ERR! Found: react@17.0.2
       npm ERR! node_modules/react
       npm ERR!   react@"^17.0.2" from the root project
       npm ERR!   peer react@">=16.3.2" from @restart/context@2.1.4
       npm ERR!   node_modules/@restart/context
       npm ERR!     @restart/context@"^2.1.4" from react-bootstrap@1.6.3
       npm ERR!     node_modules/react-bootstrap
       npm ERR!       react-bootstrap@"^1.6.3" from the root project
       npm ERR!   15 more (@restart/hooks, @testing-library/react, ...)
       npm ERR! 
       npm ERR! Could not resolve dependency:
       npm ERR! peer react@"^0.14.0 || ^15.0.0 || ^16.0.0-0" from react-html-parser@2.0.2
       npm ERR! node_modules/react-html-parser
       npm ERR!   react-html-parser@"^2.0.2" from the root project
       npm ERR! 
       npm ERR! Conflicting peer dependency: react@16.14.0
       npm ERR! node_modules/react
       npm ERR!   peer react@"^0.14.0 || ^15.0.0 || ^16.0.0-0" from react-html-parser@2.0.2
       npm ERR!   node_modules/react-html-parser
       npm ERR!     react-html-parser@"^2.0.2" from the root project
       npm ERR! 
       npm ERR! Fix the upstream dependency conflict, or retry
       npm ERR! this command with --force, or --legacy-peer-deps
       npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
       npm ERR! 
       npm ERR! See /tmp/npmcache.kZUSj/eresolve-report.txt for a full report.

       npm ERR! A complete log of this run can be found in:
       npm ERR!     /tmp/npmcache.kZUSj/_logs/2024-03-13T22_30_30_613Z-debug-0.log
-----> Build failed
timofeysie commented 8 months ago

ChatGPT suggest the following to resolve this issue, you can try the following steps:

  1. Update the react-html-parser package to a version that supports React 17. You can check if there is a newer version available that is compatible with React 17 by visiting the package's page on the npm registry or checking the GitHub repository.
  2. If a compatible version is not available, you can try to update the conflicting packages that depend on React to versions that support React 17. In this case, the @restart/context package is causing the conflict. Check if there is a newer version of @restart/context available that supports React 17. If so, update the version in your project's dependencies.
  3. If updating the conflicting packages is not possible or doesn't resolve the issue, you can try using the --legacy-peer-deps flag when running the Heroku build. This flag allows npm to use an older, potentially incorrect dependency resolution that might work in this case. You can add the flag by modifying your Heroku build command in the package.json file: "scripts": { "heroku-postbuild": "npm install --legacy-peer-deps && react-scripts build" } With this change, the npm install command during the Heroku build will use the --legacy-peer-deps flag to potentially resolve the dependency conflict.
timofeysie commented 8 months ago

Both react-html-parser and html-react-parser caused build failures I could not fix, so resorted to a basic approach:

{content && <Card.Text><div dangerouslySetInnerHTML={{ __html: content }} /></Card.Text>}