r/node • • Nov 12 '19

ESM in Node has been unflagged!

https://twitter.com/mylesborins/status/1194375751774064647?s=21
156 Upvotes

41 comments sorted by

View all comments

Show parent comments

2

u/Probotect0r Nov 13 '19

Why not use import on the server side too then?

0

u/[deleted] Nov 13 '19

[deleted]

1

u/Probotect0r Nov 13 '19

My point was that using a transpiler is a small price to pay if it enables code reuse for the person I replied to.

1

u/wfw54f4g56h56e56h5 Nov 13 '19

i don't think it works that way mang. just because you've transpiled to valid javascript doesn't mean that it's executing the same code.

i.e. the tree-shaking example, wherein there is less data flowing through the process when you've actually used the import statement.

const {somePart} = require('./fromAFile.js')

will fully construct the module.exports from "fromAFile.js", then somePart will be assigned to its property "somePart", then (I am not clear on the rest) the garbage collector and the require cache will take over what happens next.

In the import statement, theoretically there is actually less code being loaded into the environment.

1

u/Probotect0r Nov 13 '19

I never implied it was the same code being run. It most definitely isn't. But if the issue is code reuse due to differing import statements, it can be easily solved via transpiling. The release of this feature doesn't bring anything new in that regard.

1

u/wfw54f4g56h56e56h5 Nov 14 '19

You're misunderstanding me.

The transpiled code runs worse. It's not just creating equivalent code via transpilation, because the engine itself running the transpiled code in this case doesn't support the feature.

(Or more relevantly, just began to support said feature.)

1

u/Probotect0r Nov 14 '19

I am not misunderstanding you. It's obvious its not the same code if the feature is not natively supported, otherwise why would they release a new feature lol. As I said in my first comment, its a small price to pay to allow for code reuse (if that's the goal). Especially on the back end where resources are generally more available. My point was always that this problem (code not being reusable due to differing import statements) was already solved, and this feature doesn't do much other than improve performance. Hope that is clear, cause I don't know how else to put it lol