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

TypeError: Cannot assign to read only property 'exports' of object '#<Object>' #1862

Open
angela318 opened this issue Jul 7, 2024 · 2 comments

Comments

@angela318
Copy link

angela318 commented Jul 7, 2024

Current Behavior

I tried to import ReactPlayer to my react rails app. I added the line below:
import ReactPlayer from 'react-player' and the page cannot be loaded. I saw the error below in console:

TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
    at Module.<anonymous> (utils.js:126:1)
    at ./node_modules/react-player/lib/utils.js (utils.js:368:1)
    at __webpack_require__ (index-07d9361752105ff10b68.js:64:30)
    at ./node_modules/react-player/lib/players/index.js (index.js:81:1)
    at __webpack_require__ (index-07d9361752105ff10b68.js:64:30)
    at ./node_modules/react-player/lib/index.js (index.js:81:1)
    at __webpack_require__ (index-07d9361752105ff10b68.js:64:30)

It fails at this line:
module.exports = __toCommonJS(utils_exports);

Expected Behavior

I want to use ReactPlayer to play a video but it fails at importing

Steps to Reproduce

I just add the line below into my app and the page error out:
import ReactPlayer from 'react-player'

Environment

  • URL attempting to play:
    localhost
  • Browser: Chrome
  • Operating system: macOS 13.5.1

Other Information

node version: v14.21.3
yarn version: v1.22.19

babel.config.js:

module.exports = function(api) {
  var validEnv = ['development', 'test', 'production']
  var currentEnv = api.env()
  var isDevelopmentEnv = api.env('development')
  var isProductionEnv = api.env('production')
  var isTestEnv = api.env('test')

  if (!validEnv.includes(currentEnv)) {
    throw new Error(
      'Please specify a valid `NODE_ENV` or ' +
        '`BABEL_ENV` environment variables. Valid values are "development", ' +
        '"test", and "production". Instead, received: ' +
        JSON.stringify(currentEnv) +
        '.'
    )
  }

  return {
    presets: [
      isTestEnv && [
        '@babel/preset-env',
        {
          targets: {
            node: 'current'
          },
          modules: 'commonjs'
        },
        '@babel/preset-react'
      ],
      (isProductionEnv || isDevelopmentEnv) && [
        '@babel/preset-env',
        {
          forceAllTransforms: true,
          useBuiltIns: 'entry',
          corejs: 3,
          modules: false,
          exclude: ['transform-typeof-symbol']
        }
      ],
      [
        '@babel/preset-react',
        {
          development: isDevelopmentEnv || isTestEnv,
          useBuiltIns: true
        }
      ]
    ].filter(Boolean),
    plugins: [
      'babel-plugin-macros',
      '@babel/plugin-syntax-dynamic-import',
      isTestEnv && 'babel-plugin-dynamic-import-node',
      '@babel/plugin-transform-destructuring',
      [
        '@babel/plugin-proposal-class-properties',
        {
          loose: true
        },
      ],
      [
        '@babel/plugin-proposal-private-methods',
        {
          loose: true
        }
      ],
      [
        '@babel/plugin-proposal-object-rest-spread',
        {
          useBuiltIns: true
        }
      ],
      [
        '@babel/plugin-transform-runtime',
        {
          helpers: false,
          regenerator: true,
          corejs: false
        }
      ],
      [
        '@babel/plugin-transform-regenerator',
        {
          async: false
        }
      ],
      isProductionEnv && [
        'babel-plugin-transform-react-remove-prop-types',
        {
          removeImport: true
        }
      ]
    ].filter(Boolean)
  }
}

webpack.config

const path = require('path');
module.exports = {
  mode: 'production',
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
  },
  module: {
    rules: [
      {
        test: /\.js$/i,
        include: path.resolve(__dirname, 'src'),
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env'],
          },
        },
      },
      {
        test: /\.css$/i,
        include: path.resolve(__dirname, 'src'),
        use: ['style-loader', 'css-loader', 'postcss-loader'],
      },
      {
        test: /\.mp4$/,
        use: {
          loader: 'file-loader'
        }
  }
    ],
  },
  devServer: {
    contentBase: path.resolve(__dirname, 'dist'),
    watchContentBase: true,
  },
};

I don't see anyone facing the same issue, I guess it might not be related to the package. But I don't know how to debug and proceed. Please help, thanks

@briardg
Copy link

briardg commented Jul 19, 2024

I get something similar:

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

And when trying to fetcher the player/file like the example in the readme with youtube

I need to do

import ReactPlayer from 'react-player/file.js'

@angela318 if in the last two weeks you found a work around could you please keep me in touch? 🙏

thanks in advance

@angela318
Copy link
Author

I get something similar:

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

And when trying to fetcher the player/file like the example in the readme with youtube

I need to do

import ReactPlayer from 'react-player/file.js'

@angela318 if in the last two weeks you found a work around could you please keep me in touch? 🙏

thanks in advance

I haven't found any workaround and am currently using the video tag directly
Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video

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

2 participants