-1

Why in JS,
React handles importing like this

import SomeThing from '../../components/SomeComponent/SomeThing';

while
Node handles importing like this

const someThing = require('../someWhere/someThing');

Is it purely a convention?
If so, are they exchangeable?
If not, why is it important to be done so?
Is there any difference between them behind the scene, e.g. performance?

3

1 Answer 1

-1

import is ES6 that is "dumbed" down by babel to compile in all browsers require is ES5. React is using import because behind the scenes it's using babel as compiler. They are not exchangeable, in the sense that in React you can use require and import, but in node natively you can just use require.

Sign up to request clarification or add additional context in comments.

3 Comments

I think "dumbed" down is not a good phrase (require is neither smarter nor dumber than import), plus you can, with the right command line options, use import in node.
Well you can do everything with the right command, can't you? But this is an answer to a question not made. I interpret es6 => es5 as "dumbed" down, you may interpret the contents of " " as you wish.
require() is not related to the ES5 spec. import can also be used in NodeJS "natively", although still experimental

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.