# 第三次查错

• The problem does only happen when the node modules are cached.
• When the cached modules are used, the errors seem to follow an interesting pattern: 1 out of 2 builds fail, consecutively. I think this explains the behavior you’re seeing where restarting the build makes it work. (This: build history list)
• This pattern made me think that the error might be caused by the combination of how cached contents are downloaded in the VM (this is, when the cache is downloaded and set up, I assume the order in which files are included might vary) AND, maybe, the order in which NPM is detecting these cached modules.
• Something I noticed is that, in these builds, NPM install seems to be returning a different output in each of them, where the order of these hexo packages varies.
• I found that, when the packages are installed in the same order, the problem does not happen:
install:
- npm install hexo-cli -g --save
- npm install hexo-helper-qrcode
- npm install hexo-generator-feed
- npm install hexo-deployer-git
- npm install hexo-prism-plugin
- npm install hexo-generator-search
- npm install hexo
- npm install hexo-generator-sitemap

As a bit more information, the order in which NPM installs packages, in general, is not deterministic since this shouldn’t be relevant. However, it seems this is causing some differences here and I wonder if this might be related to a Hexo bug, as it happened here: https://github.com/hexojs/hexo/issues/2076

Something I also noticed is that your package.json doesn’t seem to be up-to-date with these installed packages, see the updates after the npm installs.

After deleting the package-lock.json file during the build, I could obtain several working builds in a row and the intermittent failures didn’t appear: See builds. This seems to reinforce the hypothesis that the way NPM is treating these dependencies, non-deterministically, might be causing these errors.

# 总结

• Start a new and clean environment at local

$npm install hexo-cli -g --save • Create a new folder and input hexo init • Install all the npm dependencies I need (installation commands all coms from .travis.yml ) 这一步使用了这些指令： $ npm install hexo hexo-deployer-git hexo-prism-plugin hexo-helper-qrcode hexo-generator-search hexo-generator-sitemap hexo-generator-feed --save
• Copy the package.json and package-lock.json to the existing repo
and replace the old ones
• Change install stage commands.

install:
- npm install hexo-cli -g --save
- npm install