I am currently learning react and I have an app using webpack, babel and react. It seems react has two ways of writing it using either required
or import
. It also seems there is a lot more documentation on using import
. How can I change my stack to use the import version?
Asked
Active
Viewed 1,291 times
1

Jamie
- 1,909
- 3
- 22
- 47
-
I think you want to know difference between `require` and `import`. – Pardeep Dhingra Aug 07 '17 at 09:45
-
This may help you https://stackoverflow.com/questions/31354559/using-node-js-require-vs-es6-import-export – Pardeep Dhingra Aug 07 '17 at 09:45
2 Answers
0
import
is ES6 (or ES2015) standard. To use it, you need to install and activate the preset in babel.
Follow these steps:
- Go to your project folder then type this:
npm install --save-dev babel-cli babel-preset-env
Create a file named
.babelrc
(in case you have not created one) and insert this lines:{ 'presets': ['env', 'react'] }
I assume you have setup the webpack to work with babel.

Win
- 2,083
- 2
- 11
- 14