Netlify deploy throws: Error: Invalid version: “1”

Netlify deploy throws: Error: Invalid version: “1”

从昨天开始,我就遇到了一个错误,我无法修复或找不到相关信息。我可以在本地毫无错误地构建我的站点,但是当我尝试在 Netlify 中部署它时,它失败并抛出:

8:19:33 AM: ​
8:19:33 AM: ┌─────────────────────────────┐
8:19:33 AM: │        Netlify Build        │
8:19:33 AM: └─────────────────────────────┘
8:19:33 AM: ​
8:19:33 AM: ❯ Version
8:19:33 AM:   @netlify/build 2.0.20
8:19:33 AM: ​
8:19:33 AM: ❯ Flags
8:19:33 AM:   deployId: 5efc2a7760231502ad0a057d
8:19:33 AM:   mode: buildbot
8:19:33 AM: ​
8:19:33 AM: ❯ Current directory
8:19:33 AM:   /opt/build/repo
8:19:33 AM: ​
8:19:33 AM: ❯ Config file
8:19:33 AM:   /opt/build/repo/netlify.toml
8:19:33 AM: ​
8:19:33 AM: ❯ Context
8:19:33 AM:   production
8:19:33 AM: ​
8:19:33 AM: ┌─────────────────────────────┐
8:19:33 AM: │     Core internal error     │
8:19:33 AM: └─────────────────────────────┘
8:19:33 AM: ​
8:19:33 AM:   Error message
8:19:33 AM:   Error: Invalid version: "1"
8:19:33 AM: ​
8:19:33 AM:   Error location
8:19:33 AM:       at Object.fixVersionField (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/normalize-package-data/lib/fixer.js:191:13)
8:19:33 AM:       at /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/normalize-package-data/lib/normalize.js:32:38
8:19:33 AM:       at Array.forEach (<anonymous>)
8:19:33 AM:       at normalize (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/normalize-package-data/lib/normalize.js:31:15)
8:19:33 AM:       at module.exports (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/read-pkg/index.js:20:36)
8:19:33 AM:       at async module.exports (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/read-pkg-up/index.js:14:16)
8:19:33 AM:       at async getPackageJson (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/utils/package.js:7:22)
8:19:33 AM:       at async build (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/core/main.js:61:46)
8:19:33 AM:       at async runCli (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/core/bin.js:17:29)
8:19:33 AM: ​
8:19:33 AM:   Error properties
8:19:33 AM:   { name: 'Error' }
8:19:33 AM: ​
8:19:33 AM: Caching artifacts
8:19:33 AM: Started saving node modules
8:19:33 AM: Finished saving node modules
8:19:33 AM: Started saving build plugins
8:19:33 AM: Finished saving build plugins
8:19:33 AM: Started saving yarn cache
8:19:33 AM: Finished saving yarn cache
8:19:33 AM: Started saving pip cache
8:19:33 AM: Finished saving pip cache
8:19:33 AM: Started saving emacs cask dependencies
8:19:33 AM: Finished saving emacs cask dependencies
8:19:33 AM: Started saving maven dependencies
8:19:33 AM: Finished saving maven dependencies
8:19:33 AM: Started saving boot dependencies
8:19:33 AM: Finished saving boot dependencies
8:19:34 AM: Started saving go dependencies
8:19:35 AM: Finished saving go dependencies
8:19:39 AM: Error running command: Build script returned non-zero exit code: 1
8:19:39 AM: Failing build: Failed to build site
8:19:39 AM: Failed during stage 'building site': Build script returned non-zero exit code: 1
8:19:39 AM: Finished processing build request in 2m10.478232047s

这似乎与节点版本有关,所以我尝试通过添加 .nvmrc 来修复,但错误仍然存​​在。两者(本地和 Netlify)都是 运行 节点版本 12.16.3

当然,我也试过在清除缓存的情况下构建。

这个问题没有提供更多信息,所以我有点迷茫。

根据 https://github.com/netlify/build/issues/1608,这是一个已知问题,应该在下一个 Netlify 版本中修复。同时,您可以通过将 package.json 中的 version 字段从 1 更改为 1.0.0 来轻松修复它:

"version": "1.0.0",

这是因为,根据npm documentation

Version must be parseable by node-semver, which is bundled with npm as a dependency. (npm install semver to use it yourself.)