Check out a free preview of the full Deno First Look course
The "npm Packages Compatibility" Lesson is part of the full, Deno First Look course featured in this preview video. Here's what you'd learn in this lesson:
Burke discusses Deno's compatibility with npm packages and built-node modules. Questions regarding specifying package versions and the meaning of "thinking like a browser" are also covered in this segment.
Transcript from the "npm Packages Compatibility" Lesson
[00:00:00]
>> Now, I hear a lot of pushback from this on people who don't like this, because they say, but I can't install the module if I'm on an aeroplane. [LAUGH] But that's true. That's true. You can't install a Deno dependency when you're on an aeroplane, but you also can't install an npm module if you're on an aeroplane.
[00:00:21]
So nothing really changes there. npm packages have to be downloaded, Deno dependencies have to be downloaded period. The only difference is that Deno uses the URL and an npm and actually copies the file to your project in the node_modules folder. If you're still not convinced, just go back to the React story that we talked about in the beginning.
[00:00:46]
Where, at one point in time, putting JavaScript in html was considered bad, and today we put JavaScript in html, we don't think twice. And so, I'm not saying that Deno is the reactive of JavaScript on all times, I'm not saying it's the right way to do it. I'm simply saying that, importing few URLs could be a better developer experience.
[00:01:09]
It could be, so give it a chance. I do think that you'll find that it's a relatively simple solution to the dependency problem, which is a thing. All right, let's talk about Compatibility With Node, because the next question that comes up real quickly is like okay. So but what about all the npm packages?
[00:01:32]
Right? Like I don't just use node i have a lot of different things that I need to use. Can I use npm packages with node? Probably not is the answer. Deno does have a node compatibility module in its standard library. In fact, if we jump out and take a look at it.
[00:01:49]
You can see here that it's meant to have a compatibility layer. So they're working on it. And then they go back and they look at, sort of checking off what did they support today, and you can see here out of 38 built in node modules, only eight are currently supported in Deno Deno Deno, although that's probably changed since I wrote that.
[00:02:14]
But you can see that they're working on it. But some things are just never gonna work. If you use a Module that has native bindings and has to be built, then it gets built with node.gyp in Node. And in Deno, it gets built with Cargo. These are just different build systems.
[00:02:37]
And so these modules are not going to be they're not going to work across these two different runtimes but I think that the third party list in Deno is growing pretty quickly. And in fact, my very least favorite new module that requires node.gyp is sass, and there's the sass already for Deno.
[00:03:05]
You can use some node modules with Deno, and we're actually going to do that at some point. But it's a little bit hacky. And I don't know if it's a good idea or not, but I am going to show you how to do it here in just a minute.
[00:03:21]
So it is possible. So the question was if we're going to think like a browser, does that mean that the browser should download TypeScript files? No, I don't think so. The assertion that Ryan is making is the Denos should work mostly like a browser not not that a browser should work like Deno and so the browser doesn't support TypeScript.
[00:03:42]
So no, I don't think that's the intention. I think it's more like he's trying to stay as close as possible to those conventions. And even Deno supports some things that the browser supports natively, like fetch. So you can just do fetch inside of Deno You don't have to include some HTTP module to make a request, you just fetch just like you do in a browser.
[00:04:04]
So that's what I mean by thinking like a browser. I don't mean that the browser should work like Deno
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops