8

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. I have no idea how to remedy this problem.

I have matched versions using npm listand manually adding to my package.json, I have used winMerge to try to find differences.

My existing node_modules folder works, but if I rebuild it, it fails miserably. I am at wit's end.

Edit Node: 6.9.5 and NPM 4.2.0

Slbox
  • 10,957
  • 15
  • 54
  • 106
  • "but my project will not build" What is the error? – Konstantin A. Magg Feb 21 '17 at 15:34
  • Refer http://stackoverflow.com/a/31637621/6048928 – RaR Feb 21 '17 at 15:36
  • Possible duplicate of [how to Add my node\_module, modules into package.json](http://stackoverflow.com/questions/31636475/how-to-add-my-node-module-modules-into-package-json) – RaR Feb 21 '17 at 15:37
  • Well, it builds, but I have issues with react-router. My existing Node_Modules folder results in no errors. I can't find any differences between them except patch level dependencies for the packages I am using and the minor oddity of `babel-generator 6.22` depending on `trim-right` in my non-working folder, whereas that same package and version does not depend on `trim-right` in the working one. – Slbox Feb 21 '17 at 15:37
  • @RaR `node init` did not build a list of packages from my `node_modules` folder. I did see that thread. – Slbox Feb 21 '17 at 15:38

3 Answers3

9

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?

Frank Schmid
  • 311
  • 1
  • 6
  • Thanks very much Frank. I'll try that as soon as I can. It sounds promising. – Slbox Feb 21 '17 at 15:40
  • Any advice on using this tool when the package.json references a fork of an NPM package? It tells me all the dependencies of the forked package are extraneous in series of error messages. – Slbox Feb 21 '17 at 16:30
  • 1
    There is an issue entry for this on GitHub with a workaround: ``` Update: using full git URLs with commit hashes (instead of branch names) in package.json seems to work around this issue. For example, changing "jquery/jquery#master" to "git://github.com/jquery/jquery#73bf35ecf31867d7ed4662374121efa310cf9f8d" shrinkwraps successfully. ``` See here: https://github.com/npm/npm/issues/11736 – Frank Schmid Feb 21 '17 at 17:56
  • Thanks very much for the help. Great tips. – Slbox Feb 22 '17 at 04:38
  • Hello @FrankSchmid , thank you for the solution , but i have found a problem when i try to execute the ng serve showing in the console this error : the @angular/compiler-cli package was not properly installed . – Yassine CHABLI Sep 07 '17 at 14:16
-1

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.
B.K
  • 847
  • 10
  • 6
-3

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

mairo0820
  • 5
  • 5