RussellDrives
RussellDrives

Reputation: 27

Why does the import keyword work in react and not in a normal npm init project?

What does the react library do to make importing an npm package in the front end work? You cannot do this in a plain vanilla javascript setup with npm init, it throws and error.

Upvotes: 0

Views: 179

Answers (1)

Shubhaw Kumar
Shubhaw Kumar

Reputation: 721

import and export are ES6 syntax which are not fully supported in plain Javascript. React projects generally use Babel or other transpilers to convert the latest ES6 and later syntaxes to the older and browser supported Javascript code. So, you are allowed to use import and export in React while you can't do it if you create a simple javascript project bootstrapping it through npm. However, you can configure babel in your simple project as well.

Upvotes: 1

Related Questions