babel-loader jsx SyntaxError: Unexpected token [duplicate]

Add “babel-preset-react” npm install babel-preset-react and add “presets” option to babel-loader in your webpack.config.js (or you can add it to your .babelrc or package.js: http://babeljs.io/docs/usage/babelrc/) Here is an example webpack.config.js: { test: /\.jsx?$/, // Match both .js and .jsx files exclude: /node_modules/, loader: “babel”, query: { presets:[‘react’] } } Recently Babel 6 was released and … Read more

CORS error even after setting Access-Control-Allow-Origin or other Access-Control-Allow-* headers on client side

Access-Control-Allow-Origin is a response header the server the request goes to must send. And all other Access-Control-Allow-* headers are response headers for servers to send. If you don’t control the server your request is sent to, and the problem with the response is just the lack of the Access-Control-Allow-Origin header or other Access-Control-Allow-* headers you … Read more

Passing environment-dependent variables in webpack

There are two basic ways to achieve this. DefinePlugin new webpack.DefinePlugin({ ‘process.env.NODE_ENV’: JSON.stringify(process.env.NODE_ENV || ‘development’) }), Note that this will just replace the matches “as is”. That’s why the string is in the format it is. You could have a more complex structure, such as an object there but you get the idea. EnvironmentPlugin new … Read more

The create-react-app imports restriction outside of src directory

This is special restriction added by developers of create-react-app. It is implemented in ModuleScopePlugin to ensure files reside in src/. That plugin ensures that relative imports from app’s source directory don’t reach outside of it. There is no official way to disable this feature except using eject and modify webpack config. But, most features and … Read more

Javascript object bracket notation ({ Navigation } =) on left side of assign

It’s called destructuring assignment and it’s part of the ES2015 standard. The destructuring assignment syntax is a JavaScript expression that makes it possible to extract data from arrays or objects using a syntax that mirrors the construction of array and object literals. Source: Destructuring assignment reference on MDN Object destructuring var o = {p: 42, … Read more