Node.js/npm - 无论如何判断一个包是否是纯 JS?

2023-05-15前端开发问题
12

本文介绍了Node.js/npm - 无论如何判断一个包是否是纯 JS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我注意到在尝试使用 npm 安装看似简单的节点包时(例如 nerve,一个微框架")我经常遇到某种形式的依赖痛苦.经过一番挖掘,我找到了 bcrypt 模块的问题,即显然是用 C/C++ 编写的,必须在包管理器下载后进行编译.

I've noticed that in trying to get seemingly simple node packages to install with npm (e.g. nerve, a "micro-framework") I often run into some form of dependency pain. After some digging, I tracked down the problem with nerve to the bcrypt module, which is apparently written in C/C++ and has to be compiled after the package manager downloads it.

不幸的是,如果您希望它在 Windows 上运行,答案似乎是(来自 bcrypt 问题线程之一)安装 Linux VM".所以今天早些时候我就这样做了,并开始遇到其他依赖项(你需要 某些未命名的 apt 包 在你甚至可以考虑构建之前安装,尽管安装了 GCC),然后最终在看到另一个 C 编译器错误之后(关于某些包或其他无法找到Arrays.c我想),我实际上放弃了,而是从神经转为表达.具有讽刺意味的是,在 Linux 和 Windows 上使用 npm 进行更大更复杂的快速安装却没有任何问题.

Unfortunately, it seems like if you want this to work on Windows, the answer is (from one of the bcrypt issues threads) "install a Linux VM". So earlier today I did just that, and started running into other dependencies (you need certain unnamed apt packages installed before you can even think about building, despite GCC being installed), then eventually after seeing yet another C compiler error (about some package or other not being able to find "Arrays.c" I think), I actually gave up, and switched from nerve to express instead. Ironically, the larger and more complicated express installs with npm on Linux and Windows without a single issue.

所以,我的问题是:是否有任何可用的过滤器/依赖项跟踪可以让您查看包是否具有除节点核心之外的其他依赖项?因为对我来说,node 的魅力是Javascript 中的一切",而这种东西非常令人不快地消除了这种错觉.事实上,尽管我在使用 C/C++ 方面所做的工作已经超过了我的时间,但现在每当我看到需要制作"某些东西时,我通常都会尖叫着朝另一个方向跑去.:)

So, my question is: is there any filter / dependency tracking available that lets you see if a package has additional dependencies besides node core? Because to me the allure of node is "everything in Javascript", and this kind of stuff dispels the illusion quite unpleasantly. In fact, despite having done more than my time working with C/C++, whenever I see a requirement to "make" something these days I generally run in the other direction screaming. :)

推荐答案

注意 package.json 中的scripts"字段.

Look out for the "scripts" field in the package.json.

如果它包含类似的东西

 "scripts": {
    "install": "make build",
 }

和根目录中的 Makefile,包很可能有一些必须编译和构建的本机模块.许多软件包包含一个仅用于编译测试的 Makefile.

and a Makefile in the root directory, there's a good possibility that the package has some native module which would have to be compiled and built. Many packages include a Makefile only to compile tests.

对包文件的检查并不排除必须编译和构建某些依赖项的可能性.这意味着对 package.json 中的每个依赖项、它们的依赖项等重复此过程.

This check on the package documents does not exclude the possibility that some dependency will have to be compiled and built. That would mean repeating this process for each dependency in the package.json, their dependencies and so on.

也就是说,许多模块已更新安装,无需在 Windows 上构建,仅此而已.然而,这不能保证所有的包.

That said many modules have been updated to install, without build on Windows, express for one. However that cannot be assured of all packages.

使用 Linux VM 似乎是最好的选择.在 Window 上开发 Node.js 应用程序 为您提供安装 VM、Node.js 和 Express 的分步说明.

Using a Linux VM seems to be the best alternative. Developing Node.js applications on Window gives you step by step instructions on installing a VM, Node.js and Express.

这篇关于Node.js/npm - 无论如何判断一个包是否是纯 JS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

JavaScript(js)文件字符串中丢失"\"斜线的解决方法
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转...
2024-10-17 前端开发问题
437

layui中table列表 增加属性 edit="date",不生效怎么办?
如果你想在 layui 的 table 列表中增加 edit=date 属性但不生效,可能是以下问题导致的: 1. 缺少日期组件的初始化 如果想在表格中使用日期组件,需要在页面中引入 layui 的日期组件,并初始化: script type="text/javascript" src="/layui/layui.js"/scrip...
2024-06-11 前端开发问题
455

Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)...
2024-04-20 前端开发问题
5

CoffeeScript 总是以匿名函数返回
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)...
2024-04-20 前端开发问题
13