简体   繁体   English

从现有的 Node_Modules 文件夹构建 Package.Json?

[英]Build Package.Json From Existing Node_Modules Folder?

I have a node_modules folder that works, and I have tried many permutations of package.json's that should create identical results and create extremely close results, but my project will not build.我有一个可用的 node_modules 文件夹,并且我尝试了 package.json 的许多排列,这些排列应该会产生相同的结果并产生非常接近的结果,但我的项目无法构建。 I have no idea how to remedy this problem.我不知道如何解决这个问题。

I have matched versions using npm list and manually adding to my package.json , I have used winMerge to try to find differences.我使用npm list匹配版本并手动添加到我的package.json ,我使用 winMerge 试图找到差异。

My existing node_modules folder works, but if I rebuild it, it fails miserably.我现有的 node_modules 文件夹可以工作,但如果我重建它,它就会失败。 I am at wit's end.我束手无策。

Edit Node: 6.9.5 and NPM 4.2.0编辑Node: 6.9.5NPM 4.2.0

You could try to use shrinkwrap to nail down the dependencies from your existing node_modules folder.您可以尝试使用 shrinkwrap 来确定现有 node_modules 文件夹中的依赖项。

See https://docs.npmjs.com/cli/shrinkwrap请参阅https://docs.npmjs.com/cli/shrinkwrap

It should create a npm-shrinkwrap with all versions nailed to the ones currently used in the node_modules folder with npm shrinkwrap .它应该创建一个 npm-shrinkwrap 并将所有版本固定到当前在 node_modules 文件夹中使用npm shrinkwrap shrinkwrap 的版本。

On the second system or in the second folder put the npm-shrinkwrap.json besides the package.json and try a npm install .在第二个系统或第二个文件夹中,将 npm-shrinkwrap.json 放在 package.json 旁边,然后尝试npm install In the optimal case it will recreate your modules exactly as in the existing location.在最佳情况下,它将完全按照现有位置重新创建您的模块。

If that does not help - can you post some more detailed error outputs?如果这没有帮助 - 你能发布一些更详细的错误输出吗?

You can create the package.json file in your chosen location by running:您可以通过运行以下命令在您选择的位置创建 package.json 文件:

npm init
  • You can answer the questions being asked when npm init is running or you can press enter until all the question are finished and update the questions at another time in the created package.json.您可以回答 npm init 运行时提出的问题,或者您可以按 enter 直到所有问题都完成,然后在创建的 package.json 中更新问题。
  • After the package.json file is created, create a script as suggested here .创建 package.json 文件后,按照此处的建议创建一个脚本。

After creating the script run创建脚本运行后

node script.js
  • Copy the dependencies listed in the terminal into the "dependencies": {} section of the package.json file you just created.将终端中列出的依赖项复制到您刚刚创建的 package.json 文件的“dependencies”: {} 部分。
  • Done.完毕。

You can run npm init in the same folder where node_modules is which will create a package.json followed by command prompts.您可以在 node_modules 所在的同一文件夹中运行npm init ,这将创建一个 package.json,然后是命令提示符。

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

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