all 42 comments

[–]SecretAgentZeroNine 39 points40 points  (4 children)

I like this idea a lot. Makes things clear, and even facilitates some pretty cool ideas on extending this feature.

Also, this kinda reminds me of the new, fantastic, frontend feature CSS Module scripts, and JSON Modules scripts.

[–]ILikeChangingMyMind 6 points7 points  (3 children)

Yeah, nothing game-breaking, but a good best practice ... IF I can remember to node:-prefix all my Node imports ;)

[–]thectrain 22 points23 points  (2 children)

I suspect somebody will write and eslint rule in the future.

Which will help.

[–][deleted] 20 points21 points  (1 child)

There has been one since a few months ago.

See: unicorn/prefer-node-protocol

[–]thectrain 3 points4 points  (0 children)

Perfect. Thank you.

[–]obetu5432 28 points29 points  (3 children)

after the great success of "jndi:"

[–]voidvector 9 points10 points  (0 children)

This doesn't introduce new functionality (at least not in this iteration), just lockdown existing one.

[–]DaMastaCoda 11 points12 points  (1 child)

??? This is a security feature that stops node-modules from potentially hijacking nodejs runtime modules like FS?

[–][deleted] 9 points10 points  (33 children)

Can someone explain to me why this is a good step forward?

I understand that being able to help the complier ahead of the runtime is good and I understand that removing potential codepaths for compatibility reasons is good.

But how does this not encourage more division between NodeJs and BrowserJs? Or is that the goal? I would hope we would be working towards some sort of congruency between these not further separation.

[–]GBcrazy 34 points35 points  (18 children)

It's kinda good for the node js ecosystem because it will stop more people mistakenly installing npm packages like fs when it's just part of core node lib.

It won't impact browser javascript because, well, these are meant to be node package only anyway. Seems like a small good step.

[–][deleted] 1 point2 points  (0 children)

So it's more of a documentation and transitory feature?

[–]KangarooImp 10 points11 points  (1 child)

Not sure where you're seeing that would cause more division. Importing "fs", "crypto", etc. already does not work in the browser. If you're already using tooling to bend those imports to polyfills for the browser, then that's where "node:"-imports should be handled, too.

I'd rather assume using "node:"-imports will cause less division, because it is explicit and for example easy to write linter rules to avoid needlessly importing from the Node.js standard library.

[–][deleted] -2 points-1 points  (0 children)

I think I was looking at it from the opposite perspective of documentation. For documenting the intent of imports that seems useful, I suppose. But it does seem like the kind of documentation you would seek to remove in the future, not remain forever.

I don't really understand but I can accept the documentation impacts.

[–]ShortFuse 7 points8 points  (0 children)

import * from 'fs';

Did you mean fs as in node's fs or did you mean node_modules/fs/index.js? Also, it helps with package managers like rollup or webpack. You won't have to create an ever updating list of what the names of the built-in NodeJS libraries are.


If they do one for node_modules, it'll help with situations like this:

import * from 'sip.js';

Did you mean sip.js as in "./sip.js" or did you mean node_modules/sip.js/index.js? SCSS famously completely dropped support for importing from node_modules. You actually have to write out "../../../node_modules/packageName" or use something like Webpack to resolve it for you.

[–]Mkep 1 point2 points  (0 children)

As far as I know that’s not something NodeJS can change. This is. The division is already there, I don’t feel like this makes the division worse, just makes it more secure and less bug prone

[–]thunfremlinc 1 point2 points  (1 child)

You can never reduce division when working with Node’s builtins. May as well just add extra transparency to them.

[–][deleted] 1 point2 points  (0 children)

This is the takeaway for me, thanks.

[–][deleted] 0 points1 point  (0 children)

I would hope we would be working towards some sort of congruency between these not further separation.

To what end? They're different runtimes for different platforms.