Build Package.Json From Existing Node_Modules Folder?

后端 未结 3 695
青春惊慌失措
青春惊慌失措 2020-12-11 09:45

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 m

相关标签:
3条回答
  • 2020-12-11 10:32

    You can run npm init in the same folder where node_modules is which will create a package.json followed by command prompts.

    0 讨论(0)
  • 2020-12-11 10:33

    You could try to use shrinkwrap to nail down the dependencies from your existing node_modules folder.

    See 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.

    On the second system or in the second folder put the npm-shrinkwrap.json besides the package.json and try a 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?

    0 讨论(0)
  • 2020-12-11 10:45

    You can create the package.json file in your chosen location by running:

    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.
    • After the package.json file is created, create a script as suggested here.

    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.
    • Done.
    0 讨论(0)
提交回复
热议问题