Reputation: 1357
I am trying to test one of the package locally. What I do is go the root directory of my package and run
npm pack
It creates .tgz file and I install this file via npm i <path to file>
. Now I found that some of my recent changes are missing in this .tgz file. I have made some tiny modifications in css file and those are not reflected in packaged .tgz file. I am not sure what is wrong here. I have looked into internet but all questions in SA and other resources says to use 'npm pack' to create tgz file, but not about this issue.
npm version 6.14.13
Upvotes: 6
Views: 2943
Reputation: 792
In my case it was not a case of missing a build step. I didn't have a build script in my local package. It also doesn't answer why my initial code worked but my subsequent changes were not getting picked up by the npm pack
command.
It turned out it was an npm caching issue. Even deleting the .tgz file did not help, nor did deleting the package dir in the node_modules dir itself. The main cause was npm's cache needing a call to cache clean: https://docs.npmjs.com/cli/v10/commands/npm-cache
So clearing the cache (specifically npm cache clean <key>
) solved it.
To figure out the cache key, run npm cache ls
and look for/grep the key based on the name of your package.
Another alternative is to update the version property in your local package's package.json, then updating the reference to the tgz file in your project's package.json dependencies, this will generate a new tgz file, therefore creating a new cache entry (however, not so practical a solution during development).
Upvotes: 2
Reputation: 1
Try deleting the old tgz file then again run npm run pack. It will work.
Upvotes: 0
Reputation: 834
Did you do npm run build
to build the latest code change? I encountered the same issue today and this was the step I forgot.
To troubleshoot, you can unzip the tgz and inspect the source files there directly to see if they are the latest version.
You can also look into the dist
folder in your local repository. After running npm run build
, the source code in dist
folder should reflect the latest code.
Upvotes: 3