First I will give some context to the problem.
I am developing an npm library. Inside the project folder, I have another folder called "example", for testing the library. The structure looks like below.
|- node_modules/
|- src/
|- example/
| |- node_modules/
| |- src/
| |- package.json
|- package.json
The root package.json has the dependency babel-jest
. The example/package.json has the dependency react-scripts
. When running react-scripts start
inside example directory, it gives the following error,
As far as I can understand, this is because, the package.json inside the example/ directory inherits (not sure if this is the right term) the dependencies of the root package.json.
That is, I can use a dependency installed in the root package.json, inside the src/ of the example/ This is convenient in some cases. But this is a blocker for my use case.
How can I prevent this behaviour? (without changing the directory structure)
Thank you.
You should not include folder node_modules in your . gitignore file (or rather you should include folder node_modules in your source deployed to Heroku). If folder node_modules: exists then npm install will use those vendored libraries and will rebuild any binary dependencies with npm rebuild .
While doing npm install, inside node_modules . staging folder is getting created. Reasons: This is a temporary folder where the modules will be kept untill npm downloads all the modules specified in the package. json.
npm ci can only install entire projects at a time: individual dependencies cannot be added with this command. If a node_modules is already present, it will be automatically removed before npm ci begins its install. It will never write to package. json or any of the package-locks: installs are essentially frozen.
package.lock.json. It contains basic information about the project. It describes the exact tree that was generated to allow subsequent installs to have the identical tree. It is mandatory for every project. It is automatically generated for those operations where npm modifies either node_modules tree or package.
From what I understand, Dan Abramov suggests to use SKIP_PREFLIGHT_CHECK=true
to work around this problem as there is no real fix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With