DEV Community

Cover image for Import Javascript subfolder modules like a boss.

Import Javascript subfolder modules like a boss.

Tomide Oladipo on May 17, 2020

Have you worked on a project and find yourself writing code like this? import { AddBank } from '../../../../pages/add-bank-account' As projects g...
Collapse
 
dividedbynil profile image
Kane Ong

Impressive boss up!
I can tell Deno guys are getting nervous...

Collapse
 
tomiiide profile image
Tomide Oladipo

Hahaa, I can feel them shaking in their boots.

But isn’t Deno just Node, I haven’t taken a deep dive, but I assume this would work in Deno too.

Collapse
 
dividedbynil profile image
Kane Ong • Edited

Deno ditches the package.json, so the local packages discoverability affected. For now, importing subfolder modules will remain inconvenient.

For more info:
github.com/denoland/deno_website2/...

Collapse
 
spez profile image
Abhigyan • Edited

Yep! It works. Deno was made to take NodeJS to a more advance level, but not to degrade it. Ryan Dahl has worked very efficiently on Deno. And I think it will be supported by many companies soo after its stable releases.

Thread Thread
 
dividedbynil profile image
Kane Ong

Do you mind showing us how it works in Deno?

Thread Thread
 
spez profile image
Abhigyan • Edited

It's Not the correct ⌚

I currently don't have Deno setup in my PC, and I don't even bother to. I would once when the release become quite stable and it would be the correct time to ditch NodeJS. Till then, STAY HOME STAY SAFE!

See ya!

Collapse
 
spez profile image
Abhigyan

Seems good! But I knew about it earlier.

Collapse
 
tomiiide profile image
Tomide Oladipo

That’s great, Boss man. 🚀

I’m curious, How often do you use this approach? Have you found any drawback or issues with it?

Collapse
 
spez profile image
Abhigyan

Not much! But I do use it when I work on my own projects. Because this method isn't quite popular, I can't use it at work. My office BOSS = 💩

Thread Thread
 
tomiiide profile image
Tomide Oladipo

😂😂

I would say, show him this article to backup your argument, but we prolly don’t want him to see this comment. 😀

Thread Thread
 
spez profile image
Abhigyan

🤣😂🤣 for sure my friend.

Collapse
 
jvretamero profile image
João Vitor Retamero

Nice one! Does the -S option is required?

Collapse
 
tomiiide profile image
Tomide Oladipo

Thanks!

-S is not required as npm autosaves dependencies from v5.

Collapse
 
pujux profile image
Julian Pufler

Cool idea man!! Awesome!

Collapse
 
tomiiide profile image
Tomide Oladipo

Thanks a lot, Julian.

Do you see yourself using it in your projects?

Collapse
 
pujux profile image
Julian Pufler

I don't usually get hit by that problem but I will surely keep it in mind and use it when I'm facing this in the future

Collapse
 
treasurechic profile image
Treasurechic

Nice one

Collapse
 
tomiiide profile image
Tomide Oladipo

Thanks @treasurechic . Let me know if you’ll be trying this is your projects.

Collapse
 
cybernetikweb profile image
B_kodeks

It's look like it's not possible to do with yarn…