9

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

5
  • "but my project will not build" What is the error? Commented Feb 21, 2017 at 15:34
  • Refer stackoverflow.com/a/31637621/6048928 Commented Feb 21, 2017 at 15:36
  • Possible duplicate of how to Add my node_module, modules into package.json Commented Feb 21, 2017 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. Commented Feb 21, 2017 at 15:37
  • @RaR node init did not build a list of packages from my node_modules folder. I did see that thread. Commented Feb 21, 2017 at 15:38

3 Answers 3

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?

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks very much Frank. I'll try that as soon as I can. It sounds promising.
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.
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: github.com/npm/npm/issues/11736
Thanks very much for the help. Great tips.
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 .
-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.

Comments

-3

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

3 Comments

This just creates a package.json, no? It won't populate it with the packages in an existing node_modules folder?
It creates package.json with all dependencies from node_modules.
@mairo0820 I've tried this with node v14.8.0 npm 6.14.7 with no luck. Are there any other prerequisites ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.