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

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

Open angela318 opened this issue 1 year ago • 2 comments

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

angela318 avatar Jul 07 '24 04:07 angela318