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

Importing from package causes error in build only. #164

Open
Flohhhhh opened this issue Jan 26, 2023 · 2 comments
Open

Importing from package causes error in build only. #164

Flohhhhh opened this issue Jan 26, 2023 · 2 comments

Comments

@Flohhhhh
Copy link

Flohhhhh commented Jan 26, 2023

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

@MrMYHuang
Copy link

MrMYHuang commented Apr 12, 2023

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

My workaround is this in TypeScript:

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

@Abdullah0991
Copy link

I have the same problem.

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

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

3 participants