Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable strict mode while bundling React using webpack

Hello I am stuck with my application, my application working fine in all other browser not in IE it's throw the error

0x800a0416 - JavaScript runtime error: Multiple definitions of a property not allowed in strict mode

I have implemented loader in webpack.config

  module: {
    loaders: [{
        test: /\.js?$/,
        exclude: /(node_modules|bower_components)/,
        loaders: ['babel'],
        include: path.join(__dirname, 'scripts')
    }]
}

and my Package.json Script contain "build": "./node_modules/.bin/webpack --config webpack.config.production.js --progress --profile --colors", for build the bundle

If I will explicitly find use strict and remove it from bundle then it works fine so how can I remove that strict mode while create a bundle using webpack

like image 573
Dhaval Patel Avatar asked Jan 20 '16 17:01

Dhaval Patel


People also ask

Can react team add the ability to disable strict mode?

If react team can add the ability to disable strict mode for those libraries it would be great Sorry, something went wrong. React can’t detect which components are “third party”.

What does the mode configuration option do in Webpack?

Providing the mode configuration option tells webpack to use its built-in optimizations accordingly. Provide the mode option in the config: or pass it as a CLI argument: The following string values are supported: Sets process.env.NODE_ENV on DefinePlugin to value development. Enables useful names for modules and chunks.

Does strictmode work with header and footer components?

In the above example, strict mode checks will not be run against the Header and Footer components. However, ComponentOne and ComponentTwo, as well as all of their descendants, will have the checks. StrictMode currently helps with: Additional functionality will be added with future releases of React.

What is strict mode in strict mode?

Strict Mode. StrictMode is a tool for highlighting potential problems in an application. Like Fragment, StrictMode does not render any visible UI. It activates additional checks and warnings for its descendants. Note: Strict mode checks are run in development mode only; they do not impact the production build.


3 Answers

Check out this package: https://www.npmjs.com/package/babel-plugin-transform-remove-strict-mode

I was looking for a convenient way to get rid of the 'use strict' and it seems to be doing just that.

like image 73
creimers Avatar answered Oct 21 '22 16:10

creimers


I have include the blacklist option in my .babelrc file like

 blacklist: ["useStrict"]

and it's working fine.

like image 40
Dhaval Patel Avatar answered Oct 21 '22 16:10

Dhaval Patel


If you're seeing that error then most likely you've got somewhere in your codebase where you're declaring multiple properties on the same object. Disabling the alarm bell just fixes the symptom.

I've found this error to pop up if I declare duplicate properties in my JSX, e.g. when doing <MyComponent className="foo" onClick={onClick} className="foobar" /> or accidentally duplicating some other property.

Find and fix the actual error instead of just suppressing the error message. IE should tell you what line it's happening on and it shouldn't be too hard to look at what's there and figure out which component has the problem.

like image 25
ivarni Avatar answered Oct 21 '22 17:10

ivarni