如何修复 Netlify 上的 node-sass 构建错误?

How to fix this node-sass build error on Netlify?

我过去做过很多次,我在 netlify 日志中收到此错误。我尝试部署的回购是 https://github.com/yanyamz/Key_Visual_Arts.

我查看它是否在 Netlify 的大小限制范围内,总共 15mb 左右,而您可以在 netlify 上部署 20+mb。

12:03:03 PM: Build ready to start
12:03:04 PM: build-image version: fa439ad1ab9393b2c0d449d8d7c033927683f4b0
12:03:04 PM: build-image tag: v4.3.0
12:03:04 PM: buildbot version: 0f2f658d862cfe72bae7cc05c6a8de0426a5a0e2
12:03:04 PM: Fetching cached dependencies
12:03:05 PM: Failed to fetch cache, continuing with build
12:03:05 PM: Starting to prepare the repo for build
12:03:05 PM: No cached dependencies found. Cloning fresh repo
12:03:05 PM: git clone https://github.com/yanyamz/Key_Visual_Arts
12:03:07 PM: Preparing Git Reference refs/heads/main
12:03:07 PM: Parsing package.json dependencies
12:03:08 PM: 
​
❯ Initial build environment
baseRelDir: true
branch: main
context: production
cwd: /opt/build/repo
featureFlags: []
mode: buildbot
repositoryRoot: /opt/build/repo
siteId: 9cc686ee-a337-4ebf-886c-99acf9adfe45
​
❯ UI build settings
baseRelDir: true
build:
  command: npm run build
  environment:
    - NETLIFY_BUILD_DEBUG
  publish: dist
​
❯ Resolved build environment
branch: main
buildDir: /opt/build/repo
context: production
env: []
​
❯ Resolved config
build:
  command: npm run build
  commandOrigin: ui
  environment:
    - NETLIFY_BUILD_DEBUG
  publish: /opt/build/repo/dist
  publishOrigin: ui

12:03:08 PM: Starting build script
12:03:08 PM: Installing dependencies
12:03:08 PM: Python version set to 2.7
12:03:09 PM: Downloading and installing node v16.8.0...
12:03:09 PM: Downloading https://nodejs.org/dist/v16.8.0/node-v16.8.0-linux-x64.tar.xz...
12:03:09 PM: Computing checksum with sha256sum
12:03:09 PM: Checksums matched!
12:03:12 PM: Now using node v16.8.0 (npm v7.21.0)
12:03:12 PM: Started restoring cached build plugins
12:03:12 PM: Finished restoring cached build plugins
12:03:12 PM: Attempting ruby version 2.7.2, read from environment
12:03:13 PM: Using ruby version 2.7.2
12:03:14 PM: Using PHP version 8.0
12:03:14 PM: Started restoring cached node modules
12:03:14 PM: Finished restoring cached node modules
12:03:14 PM: Installing NPM modules using NPM version 7.21.0
12:03:16 PM: npm WARN old lockfile
12:03:16 PM: npm WARN old lockfile The package-lock.json file was created with an old version of npm,
12:03:16 PM: npm WARN old lockfile so supplemental metadata must be fetched from the registry.
12:03:16 PM: npm WARN old lockfile
12:03:16 PM: npm WARN old lockfile This is a one-time fix-up, please be patient...
12:03:16 PM: npm WARN old lockfile
12:03:18 PM: npm WARN old lockfile vue-loader-v16: No matching version found for vue-loader-v16@16.5.0.
12:03:18 PM: npm WARN old lockfile     at module.exports (/opt/buildhome/.nvm/versions/node/v16.8.0/lib/node_modules/npm/node_modules/npm-pick-manifest/index.js:209:23)
12:03:18 PM: npm WARN old lockfile     at /opt/buildhome/.nvm/versions/node/v16.8.0/lib/node_modules/npm/node_modules/pacote/lib/registry.js:118:26
12:03:18 PM: npm WARN old lockfile     at async Array.<anonymous> (/opt/buildhome/.nvm/versions/node/v16.8.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:691:9)
12:03:18 PM: npm WARN old lockfile  Could not fetch metadata for vue-loader-v16@16.5.0 vue-loader-v16: No matching version found for vue-loader-v16@16.5.0.
12:03:18 PM: npm WARN old lockfile     at module.exports (/opt/buildhome/.nvm/versions/node/v16.8.0/lib/node_modules/npm/node_modules/npm-pick-manifest/index.js:209:23)
12:03:18 PM: npm WARN old lockfile     at /opt/buildhome/.nvm/versions/node/v16.8.0/lib/node_modules/npm/node_modules/pacote/lib/registry.js:118:26
12:03:18 PM: npm WARN old lockfile     at async Array.<anonymous> (/opt/buildhome/.nvm/versions/node/v16.8.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:691:9) {
12:03:18 PM: npm WARN old lockfile   code: 'ETARGET',
12:03:18 PM: npm WARN old lockfile   type: 'version',
12:03:18 PM: npm WARN old lockfile   wanted: '16.5.0',
12:03:18 PM: npm WARN old lockfile   versions: [
12:03:18 PM: npm WARN old lockfile     '16.0.0-beta.5',
12:03:18 PM: npm WARN old lockfile     '16.0.0-beta.5.1',
12:03:18 PM: npm WARN old lockfile     '16.0.0-beta.5.2',
12:03:18 PM: npm WARN old lockfile     '16.0.0-beta.5.3',
12:03:18 PM: npm WARN old lockfile     '16.0.0-beta.5.4'
12:03:18 PM: npm WARN old lockfile   ],
12:03:18 PM: npm WARN old lockfile   distTags: { latest: '16.0.0-beta.5.4' },
12:03:18 PM: npm WARN old lockfile   defaultTag: 'latest'
12:03:18 PM: npm WARN old lockfile }
12:03:33 PM: npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
12:03:33 PM: npm WARN deprecated har-validator@5.1.5: this library is no longer supported
12:03:33 PM: npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
12:03:34 PM: npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
12:03:35 PM: npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
12:03:37 PM: npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
12:03:38 PM: npm WARN deprecated eslint-loader@2.2.1: This loader has been deprecated. Please use eslint-webpack-plugin
12:03:39 PM: npm WARN deprecated html-webpack-plugin@3.2.0: 3.x is no longer supported
12:03:40 PM: npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
12:03:40 PM: npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
12:03:40 PM: npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
12:03:41 PM: npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
12:03:42 PM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
12:03:42 PM: npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
12:03:42 PM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
12:03:43 PM: npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
12:03:43 PM: npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
12:06:00 PM: npm ERR! code 1
12:06:00 PM: npm ERR! path /opt/build/repo/node_modules/node-sass
12:06:00 PM: npm ERR! command failed
12:06:00 PM: npm ERR! command sh -c node scripts/build.js
12:06:00 PM: npm ERR! Building: /opt/buildhome/.nvm/versions/node/v16.8.0/bin/node /opt/build/repo/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
12:06:00 PM: npm ERR! make: Entering directory '/opt/build/repo/node_modules/node-sass/build'
12:06:00 PM: npm ERR!   g++ '-DNODE_GYP_MODULE_NAME=libsass' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' 

停止使用node-sass

  1. 它是本机节点包,这意味着它需要在某些环境中安装一些构建工具(某些 OS/environments 的预构建二进制文件在 NPM 包中分发,但显然不是用于一个使用通过 netlify)

  2. 除此之外已经是deprecated

只需卸载 node-sass 并安装 sass - sass-loader 应该会自动切换到它

此错误是由节点 16.x 上的 Netifly 环境 运行 引起的(请参阅您的日志“下午 12:03:12:现在使用节点 v16.8.0 (npm v7.21.0)” ) 与您正在使用的 node-sass 版本不兼容。

你可以参考这个:

您还可以在此处验证节点版本与节点-sass 之间的兼容性:https://www.npmjs.com/package/node-sass

只需卸载 node-sass 并安装 sass-loader 和 sass

npm uninstall node-sass
npm install sass-loader
npm install sass

一切都一样!再次部署,这次不会显示错误。