svgr/webpack Not Working With Webpack 5 and SingleSpa - reactjs

I been struggling with this for a week, I been reading another Stackoverflow questions and the SVGR/WEBPACK documentation but I'm unable to solve this.
I wanted to upgrade an old react single-spa application but it had a lot of conflicting dependencies so I simply went and created a new one using the Single Spa Playground web application, everything works great but I can't get my SVG'S as React Components with SVGR/WEBPACK.
The error:
webpack.config.js
const webpackMerge = require("webpack-merge").merge;
const singleSpaDefaults = require("webpack-config-single-spa-react-ts");
module.exports = (webpackConfigEnv, argv) => {
const defaultConfig = singleSpaDefaults({
orgName: "testorg",
projectName: "testproj",
webpackConfigEnv,
argv,
});
return webpackMerge(defaultConfig, {
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: ["style-loader", "css-loader", "sass-loader"],
},
{
test: /\.svg$/,
use: ["#svgr/webpack"],
},
],
},
});
};
How I'm importing the svg
import TestImg from "../../assets/icons/testimage.svg";
How I'm using the SVG
<TestImg />
declarations.d.ts
I'm not entirely sure how does this works but I also removed this and it's the same.
declare module "*.svg" {
const content: React.FC<React.SVGAttributes<SVGElement>>;
export default content;
}
package.json
{
"name": "#testorg/testproj",
"scripts": {
"start": "webpack serve",
"start:standalone": "webpack serve --env standalone",
"build": "concurrently npm:build:*",
"build:webpack": "webpack --mode=production",
"analyze": "webpack --mode=production --env analyze",
"lint": "eslint src --ext js,ts,tsx",
"format": "prettier --write .",
"check-format": "prettier --check .",
"test": "cross-env BABEL_ENV=test jest",
"watch-tests": "cross-env BABEL_ENV=test jest --watch",
"prepare": "husky install",
"coverage": "cross-env BABEL_ENV=test jest --coverage",
"build:types": "tsc"
},
"devDependencies": {
"#babel/core": "^7.15.0",
"#babel/eslint-parser": "^7.15.0",
"#babel/plugin-transform-runtime": "^7.15.0",
"#babel/preset-env": "^7.15.0",
"#babel/preset-react": "^7.14.5",
"#babel/preset-typescript": "^7.15.0",
"#babel/runtime": "^7.15.3",
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^12.0.0",
"#types/testing-library__jest-dom": "^5.14.1",
"babel-jest": "^27.0.6",
"concurrently": "^6.2.1",
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-ts-react-important-stuff": "^3.0.0",
"eslint-plugin-prettier": "^3.4.1",
"husky": "^7.0.2",
"identity-obj-proxy": "^3.0.0",
"jest": "^27.0.6",
"jest-cli": "^27.0.6",
"prettier": "^2.3.2",
"pretty-quick": "^3.1.1",
"sass": "^1.56.2",
"sass-loader": "^13.2.0",
"ts-config-single-spa": "^3.0.0",
"typescript": "^4.3.5",
"webpack": "^5.75.0",
"webpack-cli": "^4.8.0",
"webpack-config-single-spa-react": "^4.0.0",
"webpack-config-single-spa-react-ts": "^4.0.0",
"webpack-config-single-spa-ts": "^4.0.0",
"webpack-dev-server": "^4.0.0",
"webpack-merge": "^5.8.0"
},
"dependencies": {
"#datepicker-react/hooks": "^2.8.4",
"#svgr/webpack": "^6.5.1",
"#types/jest": "^27.0.1",
"#types/react": "^17.0.19",
"#types/react-dom": "^17.0.9",
"#types/systemjs": "^6.1.1",
"#types/webpack-env": "^1.16.2",
"date-fns": "^2.29.3",
"prop-types": "^15.8.1",
"react": "^17.0.2",
"react-datepicker": "^4.8.0",
"react-dom": "^17.0.2",
"react-modal": "^3.16.1",
"react-number-format": "^5.1.2",
"react-toastify": "^6.2.0",
"single-spa": "^5.9.3",
"single-spa-react": "^4.3.1",
"styled-components": "^5.3.6"
},
"types": "dist/testorg-testproj.d.ts"
}
The only way it works
The only way I got it working is uninstalling #svgr/webpack and using my imported svg inside of an img tag, as a source.
<img src={TestImg} alt='' width='200' height='200' />
But is not what I want, I need to be able modify the svg fill by props and that's why I need it as a React Component.
Also, I have a LOT of icons and logos in this project, so manually creating a React Component in my project for each image/icon it's not the solution I'm looking for.
Additional information 1
I put a console log for the TestImg and it shows an url, clearly it's not importing it as a component
If I go to the url this is what it shows:
Additional information 2
import { ReactComponent as TestImg } from "../../assets/icons/testimage.svg"
Doesn't work either, it says:
Can't import the named export 'ReactComponent' (imported as 'TestImg') from default-exporting module (only default export is available)

Related

NextJS & TypeScript Module parse failed: unexpected token

I've got a NextJS site running TypeScript and a component of it in a separate repo installed using npm, but when I try and use the component in the site it shows the following message:
error - ./node_modules/promotion-spot/dist/PromotionSpot/Conditional/index.jsx
Module parse failed: Unexpected token (11:8)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
The component works fine when it isn't in a separate npm dependency but, when it is, NextJS won't load it properly. The component is compiled into JavaScript with .d.ts files and I saw that react-chrono does something similar and that works in the site fine.
The component's source code is at https://github.com/Relucent-Software/promotion-spot.
Here's the package.json file for the NextJS site too:
{
"name": "thederbyinn.co.uk",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "npm-run-all test:*",
"test:eslint": "eslint --ext .ts --ext .js --ext .tsx --ext .jsx src/**/*"
},
"dependencies": {
"#types/react-gtm-module": "^2.0.1",
"animate.css": "^4.1.1",
"classnames": "^2.3.1",
"formik": "^2.2.9",
"libphonenumber-js": "^1.9.53",
"lodash.get": "^4.4.2",
"luxon": "^2.4.0",
"next": "^12.1.6",
"next-seo": "^4.29.0",
"promotion-spot": "github:Relucent-Software/promotion-spot",
"query-string": "^7.1.1",
"react": "17.0.2",
"react-chrono": "^1.15.0",
"react-dom": "17.0.2",
"react-gtm-module": "^2.0.11",
"react-icons": "^4.3.1",
"react-masonry-css": "^1.0.16",
"sass": "^1.51.0",
"schema-dts": "^1.1.0",
"swiper": "^7.4.1",
"tailwindcss": "^2.2.19",
"webfontloader": "^1.6.28"
},
"devDependencies": {
"#babel/core": "^7.17.10",
"#types/lodash.get": "^4.4.7",
"#types/lodash.has": "^4.5.7",
"#types/luxon": "^2.3.2",
"#types/node": "16.11.7",
"#types/react": "17.0.35",
"#types/react-datepicker": "^4.4.1",
"#typescript-eslint/eslint-plugin": "^5.23.0",
"#typescript-eslint/parser": "^5.23.0",
"autoprefixer": "^10.4.7",
"babel-loader": "^8.2.5",
"eslint": "^8.15.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-n": "^15.2.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.5.0",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.13",
"typescript": "4.4.4"
}
}

React Three Drei can't resolve react-dom/client 17.0.1

three version:^0.140.2
#react-three/fiber version:^8.0.19
#react-three/drei version:^9.11.0
node version:14.18.13
npm (or yarn) version: 1.22.17 (yarn)
react version:17.0.1
react-dom version:17.0.1
Problem description:
Implementing react three drei above my NextJS app getting an error when go to the page which import react three drei, like the following:
./node_modules/#react-three/drei/web/Html.js:3:0 Module not found: Can't resolve 'react-dom/client' Import trace for requested module: ./node_modules/#react-three/drei/index.js ./components/Model3D/ThreeDModel.js ./pages/new.js
Expected:
I go to 'new' page, then I can load 3d model with .glb format from HTML input tag using useGLTF
Relevant Code:
import React from 'react'
import { useGLTF } from '#react-three/drei/core/useGLTF'
import { OrbitControls } from '#react-three/drei'
import { parseImgUrl } from 'utils/common'
const Model1 = ({ threeDUrl }) => {
const loadedGltf = useGLTF(parseImgUrl(threeDUrl), true)
return (
<>
<primitive object={loadedGltf.scene} dispose={null} />
<OrbitControls />
<ambientLight />
</>
)
}
export { Model1 }
Suggested Solution:
At this time, I think root cause of the error is that my react three drei which I used don't supported react#17.0.1. I expected that previous react three drei version support react#17.0.1 then really wonder what specified version that support react#17.0.1 or maybe the error was caused by other things. Thank you for your support, that's always my pleasure.
This is the entire dependencies within package.json
{
"name": "paras-v2-landing",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"dev:testnet": "PORT=8081 dotenv -e .env.testnet next dev",
"dev:mainnet": "PORT=8082 dotenv -e .env.mainnet next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"format": "prettier --write .",
"prettier-check": "prettier --check .",
"prepare": "husky install"
},
"dependencies": {
"#draft-js-plugins/anchor": "^4.1.1",
"#draft-js-plugins/buttons": "^4.0.0",
"#draft-js-plugins/divider": "^4.1.1",
"#draft-js-plugins/editor": "^4.0.0",
"#draft-js-plugins/focus": "^4.1.0",
"#draft-js-plugins/image": "^4.0.0",
"#draft-js-plugins/inline-toolbar": "^4.1.0",
"#draft-js-plugins/linkify": "^4.1.0",
"#draft-js-plugins/static-toolbar": "^4.0.0",
"#draft-js-plugins/video": "^4.1.0",
"#react-three/drei": "^9.11.0",
"#react-three/fiber": "^8.0.19",
"#sentry/nextjs": "^6.12.0",
"#tailwindcss/line-clamp": "^0.3.1",
"axios": "^0.21.0",
"blurhash": "^1.1.3",
"cachios": "^3.0.0",
"capitalize": "^2.0.4",
"cids": "^1.1.5",
"compressorjs": "^1.0.7",
"croppie": "^2.6.5",
"draft-js": "^0.11.7",
"file-type": "^16.5.3",
"generate-avatar": "^1.4.10",
"javascript-time-ago": "^2.3.2",
"js-base64": "^3.5.2",
"js-cookie": "^2.2.1",
"jsbi": "^3.1.4",
"near-api-js": "^0.42.0",
"next": "^12.1.6",
"postcss": "^8.4.12",
"query-string": "^7.0.1",
"react": "^18.1.0",
"react-awesome-animated-number": "^1.0.6",
"react-blurhash": "^0.1.3",
"react-card-flip": "^1.1.5",
"react-content-loader": "^6.0.3",
"react-custom-scrollbars": "^4.2.1",
"react-dom": "^18.1.0",
"react-fast-marquee": "^1.1.3",
"react-google-recaptcha": "^2.1.0",
"react-hamburgers": "^1.0.0",
"react-hook-form": "^6.10.0",
"react-horizontal-scrolling-menu": "^2.7.0",
"react-infinite-scroll-component": "^5.1.0",
"react-intl": "^5.9.2",
"react-linkify": "^1.0.0-alpha",
"react-responsive-carousel": "^3.2.23",
"react-share": "^4.3.1",
"react-slick": "^0.28.1",
"react-tooltip": "^4.2.17",
"recharts": "^2.1.9",
"slick-carousel": "^1.8.1",
"swr": "^1.2.2",
"three": "^0.140.2",
"three-stdlib": "^2.10.1",
"uuid": "^8.3.2",
"zustand": "^3.1.3"
},
"devDependencies": {
"#next/bundle-analyzer": "^12.1.4",
"autoprefixer": "^10.4.4",
"dotenv-cli": "^4.1.1",
"eslint": "^7.30.0",
"eslint-config-next": "^11.0.1",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-react-hooks": "^4.2.0",
"husky": "^7.0.0",
"lint-staged": "^11.1.2",
"postcss-import": "^13.0.0",
"postcss-preset-env": "^6.7.0",
"prettier": "2.4.1",
"pretty-quick": "^3.1.2",
"tailwindcss": "^3.0.23"
},
"license": "GPL-3.0",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx}": [
"eslint --fix",
"git add"
],
"*.{html,css,less,ejs}": [
"git add"
]
}
}

Gatsby, Prismic - error Building static HTML failed for path "/blog/"

I have a website created using Gatsby v. 3.0.1 and Prismic CMS, and Github Actions for CI/CD. The build of the page on GH is triggered automatically every time content is added/edited on CMS.
Blog posts on the website are generated dynamically with gatsby-node.js createPage function:
const blog = require.resolve(
`./src/components/features/blog/post/PostDetails.tsx`
);
const result = await graphql(`
{
allPrismicBlogPost {
edges {
node {
lang
tags
data {
link {
text
}
}
}
}
}
}
`);
result?.data?.allPrismicBlogPost?.edges?.forEach(({ node }) => {
createPage({
path: `/blog/${node?.data?.link?.text}/`,
component: blog,
context: {
link: node?.data?.link?.text,
},
});
});
Couple of days ago after adding a new blog post the build failed with following error:
error Building static HTML failed for path "/blog/"
SyntaxError:Unexpected number in JSON at position 183
- JSON.parse
- render-html.js:58 readPageData
[website]/[gatsby]/dist/utils/worker/render-html.js:58:15
- render-html.js:266 async _bluebird.default.map.concurrency
[website]/[gatsby]/dist/utils/worker/render-html.js:266:24
Now every time I try to add new post the build fails, and the only way to fix this is to archive the post in Prismic. Weird thing is that this build fail doesn't happen if I edit already existing blog post, only when adding a new one.
I cannot reproduce the error locally, it only fails on Github build.
I've already looked through the blog post in order to find something that could've broken the build, like some unusual fields that weren't present in previous blog posts, reinstalled all packages, updated package-lock.json, added empty blog posts to see if this would work, looked through every file in /public folder to find some clue but nothing yet worked and the build still fails when adding new blog posts. Has anyone else had this issue and knows how to fix this?
Full stack trace:
https://pastebin.com/VbLJZk3P
My package.json:
{
"name": "gatsby-starter-default",
"private": true,
"description": "A simple starter to get up and developing quickly with Gatsby",
"version": "0.1.0",
"author": "Kyle Mathews <mathews.kyle#gmail.com>",
"dependencies": {
"-": "^0.0.1",
"#reduxjs/toolkit": "^1.5.0",
"#types/react-redux": "^7.1.16",
"#types/styled-components": "^5.1.9",
"bootstrap": "^4.6.0",
"dotenv": "^8.2.0",
"gatsby": "^3.0.1",
"gatsby-plugin-alias-imports": "^1.0.5",
"gatsby-plugin-force-trailing-slashes": "^1.0.5",
"gatsby-plugin-gatsby-cloud": "^2.0.0",
"gatsby-plugin-gdpr-cookies": "^2.0.8",
"gatsby-plugin-graphql-codegen": "^3.1.0",
"gatsby-plugin-manifest": "^3.0.0",
"gatsby-plugin-offline": "^4.0.0",
"gatsby-plugin-react-helmet": "^4.0.0",
"gatsby-plugin-react-svg": "^3.0.0",
"gatsby-plugin-robots-txt": "^1.6.10",
"gatsby-plugin-sass": "^4.1.0",
"gatsby-plugin-sharp": "^3.0.0",
"gatsby-plugin-sitemap": "^4.10.0",
"gatsby-plugin-social9-socialshare": "^1.0.5",
"gatsby-source-filesystem": "^3.0.0",
"gatsby-source-prismic": "^3.3.4",
"gatsby-transformer-sharp": "^3.0.0",
"graphql": "^15.5.0",
"graphql-cli": "3.0.14",
"graphql-request": "^3.4.0",
"prismic-reactjs": "^1.3.3",
"prop-types": "^15.7.2",
"react": "^17.0.1",
"react-bootstrap": "^1.5.2",
"react-cookie-consent": "^6.2.4",
"react-dom": "^17.0.1",
"react-glider": "^2.1.1",
"react-helmet": "^6.1.0",
"react-is": "^17.0.2",
"react-media": "^2.0.0-rc.1",
"react-redux": "^7.2.2",
"react-router-dom": "^5.2.0",
"redux": "^4.0.5",
"sass": "^1.32.8",
"styled-components": "^5.2.3",
"uuid": "^8.3.2"
},
"devDependencies": {
"#types/node": "^14.14.35",
"#types/react": "^17.0.3",
"#types/react-dom": "^17.0.2",
"#types/react-helmet": "^6.1.0",
"#types/uuid": "^8.3.4",
"eslint-config-prettier": "^8.3.0",
"prettier": "^2.2.1",
"tsconfig-paths-webpack-plugin": "^3.5.1",
"typescript": "^4.2.3"
},
"keywords": [
"gatsby"
],
"license": "0BSD",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"start": "npm run develop",
"serve": "gatsby serve",
"clean": "gatsby clean",
"test": "npm run type-check && npm run lint",
"lint": "eslint . --ext .ts,.tsx",
"type-check": "tsc --pretty"
},
"repository": {
"type": "git",
"url": "https://github.com/gatsbyjs/gatsby-starter-default"
},
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
}
}

StorybookJS: Accessing non-existent addons channel

I am currently trying to add the #storybook/addon-console to Storybook.
After running npm install #storybook/addon-console #storybook/addon-actions --save-dev, I get this error when I try to run npm run storybook:
Error: Accessing non-existent addons channel, see https://storybook.js.org/basics/faq/#why-is-there-no-addons-channel
at AddonStore.getChannel (/Users/mitchell/Documents/GitHub/TapTapesWeb/node_modules/#storybook/addons/dist/cjs/index.js:53:13)
I tried to add this to my config.js file as per that link, to no avail:
import addons, { mockChannel } from '#storybook/addons';
addons.setChannel(mockChannel());
This is my Storybook main.js file:
module.exports = {
stories: ['../components/**/*.stories.#(js|jsx|ts|tsx)'],
addons: [
'#storybook/addon-links',
'#storybook/addon-essentials',
'storybook-addon-material-ui',
'#storybook/addon-postcss',
'#storybook/addon-console',
'#storybook/addon-actions'
],
reactOptions: {
fastRefresh: true
}
};
Here is my Storybook config.js file:
import theme, { muiTheme } from '../constants/theme';
import React from 'react';
import { MuiThemeProvider } from '#material-ui/core/styles';
import { ThemeProvider } from 'styled-components';
import CssBaseline from '#material-ui/core/CssBaseline';
export const decorators = [
(Story) => (
<ThemeProvider theme={theme}>
<MuiThemeProvider theme={muiTheme}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<Story />
</MuiThemeProvider>
</ThemeProvider>
)
];
Here is my package.json:
{
"name": "TapTapesWeb",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "cross-env NODE_OPTIONS='--inspect' next dev",
"build": "next build",
"start": "next start",
"test": "jest --passWithNoTests",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"format": "prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc",
"postinstall": "husky install",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.34",
"#fortawesome/free-brands-svg-icons": "^5.15.2",
"#fortawesome/free-regular-svg-icons": "^5.15.2",
"#fortawesome/free-solid-svg-icons": "^5.15.2",
"#fortawesome/react-fontawesome": "^0.1.14",
"#material-ui/core": "^4.11.3",
"#material-ui/icons": "^4.11.2",
"#material-ui/lab": "^4.0.0-alpha.57",
"#reduxjs/toolkit": "^1.5.0",
"axios": "^0.21.1",
"cross-env": "^7.0.3",
"lodash": "^4.17.21",
"next": "10.0.7",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-horizontal-scrolling-menu": "^0.7.10",
"react-redux": "^7.2.2",
"redux": "^4.0.5",
"styled-components": "^5.2.1"
},
"devDependencies": {
"#babel/core": "^7.13.1",
"#storybook/addon-actions": "^6.2.0-beta.5",
"#storybook/addon-console": "^1.2.3",
"#storybook/addon-essentials": "^6.2.0-beta.5",
"#storybook/addon-links": "^6.2.0-beta.5",
"#storybook/addon-postcss": "^2.0.0",
"#storybook/addon-viewport": "^6.2.0-beta.5",
"#storybook/addons": "^6.2.0-beta.5",
"#storybook/react": "^6.2.0-beta.5",
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.2",
"babel-plugin-styled-components": "^1.12.0",
"eslint": "^7.20.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"husky": "^5.1.1",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"storybook-addon-material-ui": "^0.9.0-alpha.24",
"storybook-addon-state": "^1.0.3"
}
}

How to make create-react-app support .mjs files with webpack?

I'm trying to work with this twitch npm package (https://www.npmjs.com/package/twitch) and am running into some issues when deploying via creat-react-app / react-scripts.
From my understanding, the webpack config that is bundled with create-react-app doesn't like .mjs files that this npm package is using. So, I get the error below when I try to build the app.
./node_modules/twitch/es/API/Kraken/Channel/ChannelApi.mjs
app_1 | Can't import the named export 'Cacheable' from non EcmaScript module (only default export is available)
If I manually deleted the "es" folder, then the build worked and everything functioned as expected. However, this isn't a real solution because when I push to production and deploy there the node modules are re-installed and the build fails once again.
Build processes aren't really my strong suit and after googling around for a while I'm unable to find a solution. If anyone can assist or can point me in the right direction, that would be much appreciated!
If it helps, here is my package.json
{
"name": "ui",
"version": "1.0.0",
"license": "UNLICENCED",
"private": true,
"dependencies": {
"#babel/core": "^7.9.0",
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
"#babel/register": "^7.0.0",
"axios": "^0.19.2",
"babel-plugin-dynamic-import-node": "^2.2.0",
"btoa": "^1.2.1",
"clipboard-copy": "^3.0.0",
"connected-react-router": "^6.8.0",
"dateformat": "^3.0.3",
"dotenv": "^8.0.0",
"draft-js": "^0.11.0",
"draft-js-export-html": "^1.4.1",
"express": "^4.16.4",
"file-loader": "^3.0.1",
"firebase": "^5.2.0",
"history": "^4.7.2",
"human-date": "^1.4.0",
"ignore-styles": "^5.0.1",
"immutability-helper": "^3.0.0",
"jwt-decode": "^2.2.0",
"lodash": "^4.17.11",
"normalizr": "^3.2.4",
"prop-types": "^15.6.1",
"qs": "^6.5.2",
"react": "^16.8.0",
"react-animations": "^1.0.0",
"react-dnd": "^7.4.5",
"react-dnd-html5-backend": "^7.4.4",
"react-dom": "^16.8.0",
"react-ga": "^2.5.3",
"react-gtm-module": "^2.0.10",
"react-helmet": "^5.2.0",
"react-image-crop": "^8.3.0",
"react-is": "^16.8.0",
"react-loadable": "^5.5.0",
"react-loading-skeleton": "^2.0.1",
"react-on-screen": "^2.1.1",
"react-pdf": "^4.0.5",
"react-pose": "^4.0.6",
"react-redux": "^6.0.1",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.0",
"react-stripe-elements": "^2.0.0",
"redux": "^4.0.0",
"redux-devtools-extension": "^2.13.2",
"redux-thunk": "^2.2.0",
"reselect": "^3.0.1",
"semantic-ui-calendar-react": "^0.15.3",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^0.87.1",
"styled-components": "^4.2.0",
"twitch": "^4.2.4",
"url-loader": "^1.1.2",
"validator": "^11.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"lint": "eslint src",
"server": "NODE_ENV=production node server/bootstrap.js"
},
"engines": {
"node": "^10.0.0",
"yarn": "^1.12.3"
},
"devDependencies": {
"#babel/plugin-proposal-class-properties": "^7.4.4",
"#babel/plugin-transform-runtime": "^7.4.4",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.8.1",
"eslint-plugin-react-hooks": "^3.0.0",
"prettier": "^2.0.2"
},
"proxy": "http://api:8080",
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"jest": {
"moduleNameMapper": {
"\\.worker.js": "<rootDir>/__mocks__/workerMock.js"
}
}
}
A suggestion presented at this GitHub comment was to add react-app-rewired to your project and then use this config-overrides.js file:
module.exports = function override(config) {
config.module.rules.push({
test: /\.mjs$/,
include: /node_modules/,
type: "javascript/auto"
});
return config;
}
In my project I was already using react-app-rewired, so I just added the rule from that snippet. This workaround fixed the error for me.
In the specific case of the twitch library, the author has suggested trying the #next release, although I haven't personally verified that solution yet.
Upgrading to the latest react-scripts version of 5.0.1 in my package.json as of writing this, has solved the issue for me.
Upgrading tolatest react-scripts version of 5.0.1 in my package.json as of writing this
use the code
npm install --save --save-exact react-scripts#5.0.1
or
yarn add --exact react-scripts#5.0.1

Resources