首页 > 解决方案 > 如何为 jquery 构建 package.json

问题描述

我是 Typescript 的新手,我想安装jquery.d.ts以便可以在我的 .ts 文件中使用 jQuery。为了获得 jquery.d.ts,我安装了 npm,然后发出命令npm install jquery。这导致了以下错误:

npm WARN saveError ENOENT:没有这样的文件或目录,打开 'C:\Users\darli\package.json'

我也尝试发出以下命令,但得到相同的结果:

npm install --save @types/jquery

搜索解决方案后,我现在明白我需要 package.json 文件来告诉 npm 安装什么。我尝试运行npm init,这导致 npm 向我询问有关我要安装的软件包的问题。我在 GitHub 上找到了实际文件,但它要求我在另一个名为 index.js 的文件中为其提供入口点,我不知道如何回答这个问题。

谁能帮我创建 package.json 文件或将我指向解释如何执行此操作的资源?在我看来,这个 package.json 文件应该很容易放在一起,因为 jquery 非常流行,但我似乎无法掌握它。

标签: jquerynpm

解决方案


You'll need to run the command npm init then you can install the jQuery package as you need.

Once you've ran npm init you will see a new file in your directory labeled package.json - this is the file that saves various information about your NPM related data. You should then be able to run your command npm install --save @types/jquery without any errors.

For more information on this process, checkout https://docs.npmjs.com/cli/init


推荐阅读