Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

npm 5.7.1 pack/publish setting timestamp to epoch #19968

Closed
1 task done
davidlehn opened this issue Mar 5, 2018 · 18 comments
Closed
1 task done

npm 5.7.1 pack/publish setting timestamp to epoch #19968

davidlehn opened this issue Mar 5, 2018 · 18 comments

Comments

@davidlehn
Copy link

davidlehn commented Mar 5, 2018

I'm opening this issue because:

  • npm is producing an incorrect install.

What's going wrong?

How can the CLI team reproduce the problem?

  • Pick a project, any project:
  • npm pack
  • tar ztvf xxx-x.y.z.tgz
-rw-rw-r-- 0/0            3487 1969-12-31 19:00 package/package.json
-rw-rw-r-- 0/0            4801 1969-12-31 19:00 package/CHANGELOG.md
...

Timestamps for all files are like new Date(0) with display adjusted for my timezone.

supporting information:

  • npm -v prints: 5.7.1
  • node -v prints: v8.9.4
  • npm config get registry prints: https://registry.npmjs.org/
  • Windows, OS X/macOS, or Linux?: Linux (Debian latest)
@marijnh
Copy link

marijnh commented Mar 8, 2018

This is pretty bad. See also acornjs/acorn#680

@charsleysa
Copy link

Just to add to the list tj/commander.js#777, according to npmjs.com package was downloaded 2,138,687 times in the last day (not specifically the broken version but has already started causing problems).

This is pretty much breaking all development and deployment systems using npm without package-lock.json (or npm-shrinkwrap.json).

@ofrobots
Copy link

ofrobots commented Mar 9, 2018

Also googleapis/google-p12-pem#27.

zkat pushed a commit that referenced this issue Mar 12, 2018
> Thank god I found you.  Listen, can you meet me at Twin Pines Mall
> tonight at 1:15?  I've made a major breakthrough, I'll need your
> assistance.

Fixes: #19933
Fixes: #19968
PR-URL: #20027
Credit: @isaacs
Reviewed-By: @zkat
@zkat zkat closed this as completed in 58d2aa5 Mar 13, 2018
@davidlehn
Copy link
Author

Great Scott! Not the solution I had expected.

@zkat
Copy link
Contributor

zkat commented Mar 13, 2018

For the curious: We started using node-tar's noMtime option, which set all the timestamps to 0. The reason for this was so two separate npm pack calls done from the same commit -- even on separate computers, would be able to generate hash-identical tarballs. We didn't really expect that random software out there would have... pathological issues with old timestamps. We still want to preserve the feature, though, so picking an arbitrary date more recent than 1980 seemed like the way to go. Hopefully there's no more incompatibilities!

OldSneerJaw added a commit to OldSneerJaw/synctos that referenced this issue Mar 20, 2018
A new version of the [commander](https://www.npmjs.com/package/commander) package is available. However, there are no functional changes in the release; it is simply a repackaging with an older version of npm to get around a [bug](npm/npm#19968) that had been introduced in npm 5.7.1. This lack of functional changes can be verified by comparing the differences in the codebase between [v2.15.0 and v2.15.1](tj/commander.js@v2.15.0...v2.15.1). Though nothing has changed, it is important to keep the dependency's version number up to date.
OldSneerJaw added a commit to OldSneerJaw/couchster that referenced this issue Mar 20, 2018
A new version of the [commander](https://www.npmjs.com/package/commander) package is available. However, there are no functional changes in the release; it is simply a repackaging with an older version of npm to get around a [bug](npm/npm#19968) that had been introduced in npm 5.7.1. This lack of functional changes can be verified by comparing the differences in the codebase between [v2.15.0 and v2.15.1](tj/commander.js@v2.15.0...v2.15.1). Though nothing has changed, it is important to keep the dependency's version number up to date.
@pleunv
Copy link

pleunv commented Apr 24, 2018

@zkat We're now experiencing packaged files having their lastModified date overwritten with Oct 26th, 1985, which is messing with cache headers. However, it's a bit of an odd one:

We have 2 package.json files that each publish a package.

  • 1 in the project root directory that publishes all source files and their deps (project/package.json)
  • 1 in the dist/ directory that publishes only bundled dist output and strips all deps (project/dist/package.json), this is for direct consumption on a static file host.

The files in the first package have a correct lastModified date, the files originating from the second package.json files are having their lastModified dates set to Oct 26th, 1985.

Any idea what could be causing this behavior?

This is on npm v5.8.0.

@pleunv
Copy link

pleunv commented Apr 24, 2018

Some further investigation:

  • The problem occurs on both Windows & OSX
  • The problem does not occur on npm 5.6.0
  • It's caused by the packaging/publishing, not the installing. For example, publishing with 5.6.0 and installing with 5.8.0 shows the correct lastModified dates, not the 1985. Publishing with 5.8.0 breaks it.

So for now I guess we'll stick to 5.6.0.

Would you like me to open a separate issue for this?

@zkat
Copy link
Contributor

zkat commented Apr 24, 2018

@pleunv: this is working as intended. We have every intention of keeping the consistent dates going forward because they enable reproducible builds for npm packages.

@pleunv
Copy link

pleunv commented Apr 24, 2018

I don't understand, how is this consistent? Depending on some variable I can't figure out (package.json location?) I'm getting all the lastModified timestamps of the installed files reset to epoch (or new equivalent) while the creation date is current. Something has to be affecting this somehow otherwise I would be seeing the same behavior when packaging from the project root, which I'm not.

Is there a specific scenario in which this is the expected outcome? Because that would already help me forward. Or, maybe easier: what is supposed to be the default behavior now? Should files be installed in node_modules with lastModified set to Oct 26th 1985?

@pleunv
Copy link

pleunv commented Apr 24, 2018

Or maybe I'm not explaining it properly, so another attempt 😄

left side: build output, creation & lastModified date = time of build
right side: after publish & install, creation date = time of build, lastModified = Oct 26th, 1985. Is this the new default behavior? Keep in mind that when using a different package.json (located one level up instead of in the dist/) the lastModified is once again equal to the time of build, which has me puzzled.

image

@ofrobots
Copy link

@pleunv what you're observing is indeed intended. Can you clarify how this default timestamp is causing you problems?

@pleunv
Copy link

pleunv commented Apr 24, 2018

The packages are pushed to a static file host, currently used in conjunction with a If-Modified-Since caching strategy. This however is based on the last-modified date, so this does not function at all with the current behavior since the server just always returns Oct 26th, 1985 10:15.

@zkat
Copy link
Contributor

zkat commented Apr 24, 2018

@pleunv the behavior now is that new packages are published with that timestamp, which means that's what you get when you extract, regardless of what version of npm you're extracting from -- what matters is what was used to pack it.

My only guess as to your inconsistency is that you're not using the npm version you think you're using to package the toplevel package (keep in mind that if you're doing this in a run-script, you might be getting an npm binary from a dependency -- try $ npx npm -v in both locations).

@pleunv
Copy link

pleunv commented Apr 24, 2018

Alright thanks, will give that a try. Guess I'll be looking for a workaround for my caching issue then :)

@zkat
Copy link
Contributor

zkat commented Apr 24, 2018

@pleunv might I recommend that you use a hash-based caching scheme, or, in lieu of that, have a run-script that touches files after an install. You can also use hook scripts to configure this in one place and only do it for individual packages as they get extracted.

@pleunv
Copy link

pleunv commented Apr 25, 2018

Hey @zkat, thanks for the tips, will take a look! The backend is not really under my control and the server is running Windows which both complicate things a little bit :)

I'm guessing a postinstall script that looks up all files and updates the mdate is probably my best bet for now.

I appreciate your time, I understand this repo is very busy :)

@wasigh
Copy link

wasigh commented May 24, 2018

Is there a CommandLine flag to disable his behaviour? We use NPM for internal used packages. And we also use this timestamp for caching purposes.
Also note that the node.js website has problems with the new behaviour:

For example: https://docs.npmjs.com/cli/build now states: "Last modified October 26, 1985"

@legodude17
Copy link
Contributor

@wasigh as @zkat said:

might I recommend that you use a hash-based caching scheme, or, in lieu of that, have a run-script that touches files after an install. You can also use hook scripts to configure this in one place and only do it for individual packages as they get extracted.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants