It was my understanding that use Babel allows you to use ecma6 javascript in an ecma5 environment by transpiling. When I use 'import' however, the 'import' is transpilied to 'require'. 'require' isn't ecma5 and requires the library 'require.js'. Therefore you can't use 'import/ export' without additional dependencies, is this correct?
Use Import Instead of Require in Node App.
And many frameworks today use Babel under the hood to compile their code. For example, Node can't use ES6 import and export statements and some other cool features of ES6 syntax without the help of a compiler like Babel.
Babel is a JavaScript compiler Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments.
_interopRequireDefault(): An ES6 CommonJS module is used as is (if it has a default export then it has a property named default). A normal CommonJS module becomes the value of the property default. In other words, in the later case, the module's exports become the default export.
Yes, Babel is just intended for translating new language features to be compatible with modern javascript engines. Babel doesn't compile to require.js module import syntax. Rather it uses the CommonJS module syntax as used by Node.js. So you could run the code directly without further build dependencies in Node.js.
As it operates on single files at a time and is a straight forward translation, it doesn't make any decisions as to how you want to include the source code of those other files into the current one.
That said, if you are going to use it in browser, you will need a build system or bundler that supports CommonJS modules statements:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With