简体   繁体   English

Freecodecamp:我被困在使用 NPM 管理包

[英]Freecodecamp: I am stuck at Manage Packages with NPM

I am on freeCodecCamp, have reachedthis challenge .我在 freeCodecCamp,已经达到了这个挑战 I have completed installing NPM, started a project and installed a module too, but I am stuck at NPM TEST which says:我已经完成了 NPM 的安装,开始了一个项目并安装了一个模块,但我被困在 NPM TEST 上,它说:

Now you've installed something, and used npm ls to show what's going on.现在你已经安装了一些东西,并使用npm ls来显示发生了什么。 If you look at the package.json file, it has this rather odd bit in it:如果你查看package.json文件,它有一个相当奇怪的地方:

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1"
},

npm can be used as a task runner, and almost every module and project will have a test script that runs to make sure everything is good. npm 可以用作任务运行器,几乎每个模块和项目都会有一个测试脚本来运行以确保一切正常。 In order to help remind you to do this, npm puts a "always failing" test in there by default.为了帮助提醒您这样做,npm 默认在其中放置了一个“总是失败”的测试。

First, create a file called test.js .首先,创建一个名为test.js的文件。 It doesn't have to do anything, really.它不需要做任何事情,真的。 (This is npm class, not testing class.) But it has to exit without throwing an error, or else the test fails. (这是 npm 类,不是测试类。)但它必须退出而不抛出错误,否则测试失败。

Then, edit your package.json file to make your scripts section look like this instead:然后,编辑您的package.json文件,使您的脚本部分看起来像这样:

"scripts": {
  "test": "node test.js"
},

Once that's done, run how-to-nom verify to check your work.完成后,运行how-to-nom verify以检查您的工作。

I tried couple of things I got online to create test.js , but I am not sure how to proceed further.我尝试了一些我在网上找到的东西来创建test.js ,但我不确定如何进一步进行。

All you have to do is create an empty test.js file and edit your package.json file.您所要做的就是创建一个空的test.js文件并编辑您的package.json文件。 Chances are you missed this step.你很可能错过了这一步。

In order to pass the test, you need to update the echo \\"Error: no test specified\\" && exit 1 line with node test.js .为了通过测试,您需要更新echo \\"Error: no test specified\\" && exit 1 line with node test.js As it is an empty file, it won't throw any error and once you run the how-to-npm verify command it will pass.因为它是一个空文件,它不会抛出任何错误,一旦你运行how-to-npm verify命令它就会通过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM