'Can't resolve 'react-dom/client' in React 17 while using React 18 library
After the release of React V18 on 29th March, we upgraded our library to be React v18 compatible, but now the library is no more compatible to be used under React V17 or React v16.
It gives the below error during consumption:
Module not found: Error: Can't resolve 'react-dom/client' in '.../node_modules/library/dist...'
What will be the right approach to create a forward and backward compatible React package?
Solution 1:[1]
Here are two ways to solve it, both assume that
triggerelements have uniquenames- a POSIX shell is used
First, an XSLT 1.0 transformation which will add a status element
from a same-named trigger in destination.xml. It's a basic
identity transform
which modifies the appropriate triggers. In case you want to limit
to certain status values you could add, for example,
and $dstat = "DISABLED" to the xsl:if test clause.
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:param name="ddoc" select="'destination.xml'"/>
<xsl:variable name="dtt" select="document($ddoc)//triggers/trigger"/>
<xsl:template match="@*|node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="triggers/trigger[not(status)]">
<xsl:variable name="dstat"
select="$dtt[name = current()/name]/status"/>
<xsl:copy>
<xsl:apply-templates/>
<xsl:if test="string($dstat)">
<xsl:copy-of select="$dstat"/>
</xsl:if>
</xsl:copy>
</xsl:template>
</xsl:transform>
Run as
xsltproc --stringparam ddoc destination.xml delta.xsl source.xml > final.xml
or
xmlstarlet tr delta.xsl -s ddoc=destination.xml source.xml > final.xml
Second, to do the same in xmlstarlet shorthand is trickier since
there are limitations on both the xmlstarlet select and xmlstarlet edit
operations: the former doesn't copy entire input, the latter doesn't
accept conditionals (except in XPath expressions). However, using
select as a code generator to produce an edit command is possible.
(To list the generated XSLT 1.0 code add -C option before -t.)
xmlstarlet sel -t \
--var sq -o "'" -b \
--var dq -o '"' -b \
--var ddoc="'destination.xml'" \
--var dtt='document($ddoc)//triggers/trigger' \
-o 'xmlstarlet edit \' -n \
-m '//triggers/trigger[not(status)]' \
--var dstat='$dtt[name = current()/name]/status' \
--if 'string($dstat)' \
-o ' -s ' -v 'concat($sq,"//triggers/trigger[name=",$dq,current()/name,$dq,"]",$sq)' \
-o ' -t elem -n status -v ' -v 'concat($sq,$dstat,$sq)' -o ' \' -n \
-b \
-b -f -n source.xml
For each status-less trigger in source.xml this command looks up
the same-named element in destination.xml having a non-empty status
element; on match emits an -s (subnode) clause for xmlstarlet edit
to target the appropriate node in source.xml. -o outputs literal
text, -n a newline, -f the input pathname, -b ends current
container (-m, --if, --var). Variables sq and dq assist in
quoting
Output:
xmlstarlet edit \
-s '//triggers/trigger[name="testtrig1"]' -t elem -n status -v 'DISABLED' \
source.xml
Run as
xmlstarlet-sel-command-above | sh -s > final.xml
to execute the output as a shell script.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | urcodebetterznow |
