Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production build error while using ReactPlayer with vite #1729

Closed
jkv27100 opened this issue Jan 2, 2024 · 4 comments
Closed

Production build error while using ReactPlayer with vite #1729

jkv27100 opened this issue Jan 2, 2024 · 4 comments

Comments

@jkv27100
Copy link

jkv27100 commented Jan 2, 2024

I attempted to integrate ReactPlayer into my project, and it functioned flawlessly on my local environment without any console errors or warnings. However, when I ran the Vite build and served the resulting build, I encountered a perplexing error message: "Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object." Upon meticulous inspection of the properties, I confirmed they were of the correct type. Interestingly, when I commented out the ReactPlayer component and rebuilt the project, the error disappeared.

I am using React 18 , react-player .2.14.1, vite 3.2.4

Here is my vite config

import fs from 'fs'
import * as path from 'path'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import rollupNodePolyFill from 'rollup-plugin-node-polyfills'
import NodeGlobalsPolyfillPlugin from '@esbuild-plugins/node-globals-polyfill'

export default () => {
return defineConfig({
plugins: [react()],
define: {
global: 'globalThis'
},
server: {
port: 3000,
proxy: 'https://pixinvent.com/',
cors: {
origin: ['https://pixinvent.com/', 'http://localhost:3000'],
methods: ['GET', 'PATCH', 'PUT', 'POST', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With']
}
},
css: {
preprocessorOptions: {
scss: {
includePaths: ['node_modules', './src/assets']
}
},
postcss: {
plugins: [require('postcss-rtl')()]
}
},
resolve: {
alias: [
{
find: /^.+/,
replacement: val => {
return val.replace(/^
/, '')
}
},
{ find: 'stream', replacement: 'stream-browserify' },
{ find: 'crypto', replacement: 'crypto-browserify' },
{ find: '@src', replacement: path.resolve(__dirname, 'src') },
{ find: '@store', replacement: path.resolve(__dirname, 'src/redux') },
{ find: '@configs', replacement: path.resolve(__dirname, 'src/configs') },
{ find: 'url', replacement: 'rollup-plugin-node-polyfills/polyfills/url' },
{ find: '@Styles', replacement: path.resolve(__dirname, 'src/@core/scss') },
{ find: 'util', replacement: 'rollup-plugin-node-polyfills/polyfills/util' },
{ find: 'zlib', replacement: 'rollup-plugin-node-polyfills/polyfills/zlib' },
{ find: '@utils', replacement: path.resolve(__dirname, 'src/utility/Utils') },
{ find: '@hooks', replacement: path.resolve(__dirname, 'src/utility/hooks') },
{ find: '@assets', replacement: path.resolve(__dirname, 'src/@core/assets') },
{ find: '@layouts', replacement: path.resolve(__dirname, 'src/@core/layouts') },
{ find: 'assert', replacement: 'rollup-plugin-node-polyfills/polyfills/assert' },
{ find: 'buffer', replacement: 'rollup-plugin-node-polyfills/polyfills/buffer-es6' },
{ find: 'process', replacement: 'rollup-plugin-node-polyfills/polyfills/process-es6' },
{ find: '@components', replacement: path.resolve(__dirname, 'src/@core/components') }
]
},
esbuild: {
loader: 'jsx',
include: /./src/..js?$/,
exclude: [],
jsx: 'automatic'
},
optimizeDeps: {
esbuildOptions: {
loader: {
'.js': 'jsx'
},
plugins: [
NodeGlobalsPolyfillPlugin({
buffer: true,
process: true
}),
{
name: 'load-js-files-as-jsx',
setup(build) {
build.onLoad({ filter: /src\.
.js$/ }, async args => ({
loader: 'jsx',
contents: await fs.readFileSync(args.path, 'utf8')
}))
}
}
]
}
},
build: {
rollupOptions: {
plugins: [rollupNodePolyFill()]
}
}
})
}

@luwes
Copy link
Collaborator

luwes commented Jan 2, 2024

please provide a code sandbox repro, you can fork this one
#1721 (comment)

ty!

@jkv27100
Copy link
Author

jkv27100 commented Jan 2, 2024

Just tried downgrading to 2.13.0. It is working fine now Thank you!

@jkv27100 jkv27100 closed this as completed Jan 2, 2024
@rahulbhanushali
Copy link

rahulbhanushali commented Jan 15, 2024

Facing the same issue with 2.13.0 as well.

Update: Was able to resolve this by upgrading to the latest version of vite.

@tb-b
Copy link

tb-b commented Jan 30, 2024

Same issue here on "vite": "5.0.12" and "react-player": "2.14.1"
Only fix I've found so far was downgrading to 2.13.0

Cannot find module './YouTube-jt1z_dY7.js'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants