react-audio-player icon indicating copy to clipboard operation
react-audio-player copied to clipboard

Importing from package causes error in build only.

Open Flohhhhh opened this issue 2 years ago • 2 comments

When running in development, I have no error and it works perfectly. Running build throws minified error below. (Even without import for audio file error still occurs)

Error:

Minified React error #130; visit https://reactjs.org/docs/error-decoder.html?invariant=130&args[]=object&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

Decoded error:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

My code:

import ReactAudioPlayer from 'react-audio-player'
import Music from './assets/audio/music.mp3'

function App() {
  return (
      <div className="app">
         <ReactAudioPlayer id="audio-controls" src={Music} autoPlay loop controls volume={0.05}/>
      </div
   }
}

Also found this error on the tsconfig.json image

Flohhhhh avatar Jan 26 '23 20:01 Flohhhhh

react-audio-player has a dep prop-types, which uses module.exports = require('xxx'). It results in a problem as shown in https://github.com/vitejs/vite/issues/2139#issuecomment-806416318

My workaround is this in TypeScript:

import AudioPlayerOrig from "react-audio-player";
const AudioPlayer = process.env.NODE_ENV === 'production' ? (AudioPlayerOrig as any).default : AudioPlayerOrig;

MrMYHuang avatar Apr 12 '23 08:04 MrMYHuang

I have the same problem.

Luckily, I saw @MrMYHuang answer :) It does solve the problem.

Abdullah0991 avatar Sep 14 '23 11:09 Abdullah0991