react-jsx-parser: Unable to build project.
Hello. Having some issues with this package. It works perfectly fine when running local in a development environment but when i build the project it crashes/not woking at all. Im getting the the error below in the console and nothing else is rendered in that component e.g the console.log in the constructur. If i remove the Jsx parser component the project works fine. Any idea what can be wrong?
TypeError: Super expression must either be null or a function
at individual-text-article.js:9
at individual-text-article.js:9
at Module.<anonymous> (individual-text-article.js:9)
at a (individual-text-article.js:9)
at e.exports (individual-text-article.js:9)
at Object.<anonymous> (individual-text-article.js:9)
at l (webpack-89179faa512dd01fbb62.js:1)
at Object.<anonymous> (individual-text-article.js:9)
at l (webpack-89179faa512dd01fbb62.js:1)
at Module.<anonymous> (individual-text-article.js:9)
package.json
"react-jsx-parser": "^1.21.0",
"react": "^16.8.0",
"react-dom": "^16.8.0",
Build script:
"next build && next start -p 8081",
Main component
import React, { Component } from 'react';
import JsxParser from 'react-jsx-parser';
import YoutubeInline from './YoutubeInline';
export default class IndividualTextArticle extends Component {
constructor(props) {
super(props);
// eslint-disable-next-line no-console
console.log('IndividualTextArticle constructor props', props);
}
....More code
render(){
return (
<JsxParser
onError={(e) => console.log('JsxParser Error: ', e)}
showWarnings={true}
components={{ YoutubeInline }}
jsx={`<YoutubeInline videoId="O8wIJd7EHMs" />`}
/>
)
}
Rendered component
import React from 'react';
const YoutubeInline = (props) => {
// eslint-disable-next-line no-console
console.log('YoutubeInline is rendered', props);
return (
<div className="col-12 col-md-10 mx-auto video-wrap xxs-mb-40 ">
<iframe
width="560"
height="315"
src={`https://www.youtube.com/embed/${props.videoId}`}
frameBorder="0"
allowFullScreen="allowFullScreen"
/>
</div>
);
};
export default YoutubeInline;
next.config.js (if relevant)
const withSass = require('@zeit/next-sass');
const nextEnv = require('next-env');
const dotenvLoad = require('dotenv-load');
dotenvLoad();
const withNextEnv = nextEnv();
module.exports = withNextEnv(
withSass({
webpack: function(config) {
config.module.rules.push({
test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
use: {
loader: 'url-loader',
options: {
limit: 100000,
name: '[name].[ext]'
}
}
});
return config;
}
})
);
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 21 (11 by maintainers)
Okay - I think I finally tracked this down. It looks like the issue is that the build is producing
umd-formatted output, and CRA (and probably other build systems) are much more likely to work usingcommonjs. Something about the difference between the two formats appears to be what’s breaking here, upon the way CRA minifies.Since so many people use CRA for their React stuff, it is important that this lib support it OOTB - so I’m going to make this lib output both a
cjsand aumdbuild, with the default beingcjs. This should make the project code you uploaded work with no changes (tested locally to verify).Thanks a ton for the repro! I would not have been able to track this down without it. 😃
I’ll add another comment shortly when I release the fix.
Same issue is happening with me. Thank you for this package, very useful and working perfectly before create-react-app builds project. Steps to re-create:
clone => https://github.com/johndangerstorey/hackthesnack run =>
npm run build && serve -s buildvisit =>localhost:5000gives blank page with errorUncaught TypeError: Super expression must either be null or a functionYes - you should be able to use:
By specifying the path, you should be able to load the
cjsversion instead of the defaultumdversion