Error: Uncaught TypeError: Cannot assign to read only proper


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

Support_Net15 asked 4 years ago

Hello,

After importing MDB Pro into my project by following the documentation on this link

"https://mdbootstrap.com/docs/standard/pro/installation/"

Knowing that I am on symfony 5 and I use Webpack Encore, the version of node I use 12.18.3 and npm -v 14.8, the build run fine without error, on the other hand on all browsers, I have the following error

Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
    at Object.<anonymous> (mdb.js:9192)
    at Object.<anonymous> (mdb.js:9195)
    at n (mdb.js:36)
    at Module.<anonymous> (mdb.js:20789)
    at n (mdb.js:36)
    at Object.<anonymous> (mdb.js:9091)
    at n (mdb.js:36)
    at mdb.js:70
    at Object.<anonymous> (mdb.js:26)
    at Object../node_modules/mdbootstrap-pro/js/mdb.js (vendors~appGlobalFrontend.js:2)

I did some research on the forum and I couldn't find a solution to my problem, please tell me what to do to resolve this problem.

My configuration files:

appGlobalFrontend.scss

@import "~mdbootstrap-pro/css/bootstrap.min.css";
@import "~@fortawesome/fontawesome-free/css/all.css";
@import '~mdbootstrap-pro/css/mdb.min.css';

appGlobalFrontend.js

import $ from 'mdbootstrap-pro/js/jquery';
import 'mdbootstrap-pro/js/popper'
import 'mdbootstrap-pro/js/bootstrap';
import * as mdb from 'mdbootstrap-pro/js/mdb'

require('@fortawesome/fontawesome-free/js/all.js');

import '../scss/appGlobalFrontend.scss';

webpack.config.js

var Encore = require('@symfony/webpack-encore');
const CopyPlugin = require('copy-webpack-plugin');
const TerserJsPlugin = require('terser-webpack-plugin');

// Manually configure the runtime environment if not already configured yet by the "encore" command.
// It's useful when you use tools that rely on webpack.config.js file.
if (!Encore.isRuntimeEnvironmentConfigured()) {
    Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}

Encore
    // directory where compiled assets will be stored
    .setOutputPath('public/build/')
    // public path used by the web server to access the output path
    .setPublicPath('/build')

    /*
     * ENTRY CONFIG
     *
     * Add 1 entry for each "page" of your app
     * (including one that's included on every page - e.g. "app")
     *
     * Each entry will result in one JavaScript file (e.g. app.js)
     * and one CSS file (e.g. app.css) if your JavaScript imports CSS.
     */
    .addEntry('appGlobalBackend', './assets/js/appGlobalBackend.js',
        {
            preload: true,
            defer: true,
            minimizer: true
        }
    )
    .addEntry('appGlobalFrontend', './assets/js/appGlobalFrontend.js',
        {
            preload: true,
            defer: true,
            minimizer: true
        }
    )


    // When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
    .splitEntryChunks()

    // will require an extra script tag for runtime.js
    // but, you probably want this, unless you're building a single-page app
    .enableSingleRuntimeChunk()

    /*
     * FEATURE CONFIG
     *
     * Enable & configure other features below. For a full
     * list of features, see:
     * https://symfony.com/doc/current/frontend.html#adding-more-features
     */
    .cleanupOutputBeforeBuild()
    .enableBuildNotifications()
    .enableSourceMaps(!Encore.isProduction())
    // enables hashed filenames (e.g. app.abc123.css)
    .enableVersioning(Encore.isProduction())

    // enables @babel/preset-env polyfills
    .configureBabelPresetEnv((config) => {
        config.useBuiltIns = 'usage';
        config.corejs = 3;
    })


    // enables Sass/SCSS support
    .enableSassLoader(function (sassOptions){}, {
        resolveUrlLoader:false
    })

    // Generate icons for different mobile
    .addPlugin(
        new CopyPlugin({
            patterns: [
                {from: './assets/media/icons', to: 'icons'},
                {from: './assets/media/logo', to: 'logo'},
                {from: './assets/media/images', to: 'images'},
            ]
        }),
    )

    // uncomment if you're having problems with a jQuery plugin
    .autoProvidejQuery()
    .autoProvideVariables({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery',
    })

    // Configure terser-webpack-plugin
    .configureTerserPlugin((options) => {
        options.cache = true;
        options.parallel = true;
        options.terserOptions = {
            output: {
                comments: false,
            },
        }
    })

    // uncomment if you use API Platform Admin (composer req api-admin)
    //.enableReactPreset()
    //.addEntry('admin', './assets/js/admin.js')
;

const webpackConfig = Encore.getWebpackConfig();
// Add the new TerserSsPlugin object
webpackConfig.plugins.push(new TerserJsPlugin());

module.exports = webpackConfig;

Thanks.


Grzegorz Bujański staff commented 4 years ago

Have you tried to import mdb.min.js replacement modules? Check out this thread: https://mdbootstrap.com/support/jquery/latest-version-of-mdb-not-compatible-with-webpack/ it can help you.


mcwnuq answered 3 years ago

Hi, have you fixed this? Just upgraded from 4.7.7 to 4.19.2 and have this issue.


Mikołaj Smoleński staff commented 3 years ago

We still don't officially support Symfony.

Keep coding, Mikołaj from MDB


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.19.1
  • Device: Any
  • Browser: Chrome, Firefox
  • OS: Ubuntu 20
  • Provided sample code: No
  • Provided link: Yes