The Will Will Web

記載著 Will 在網路世界的學習心得與技術分享

前後端專案在設定 CI 時應注意版本相依問題

昨天有個五年前的專案,由於正式環境出了一點狀況想要重新部署,但卻發現 CI 已經無法正常執行,不是版本不對就是套件異常,弄了好幾個小時才搞定。這篇文章我想分享一下這次處理的經驗與心得分享。

fixing

問題說明與解決方案

問題發生的當下,通常都不知道問題在哪裡,我處在瞎子摸象的階段大概一兩個小時左右,一直嘗試找出蛛絲馬跡。

首先,第一個錯誤如下:

##[section]Starting: Publish
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.217.0
Author       : Microsoft Corporation
Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
[command]C:\Windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
[command]"C:\Program Files\dotnet\dotnet.exe" publish D:\a\1\s\MyProject.csproj --configuration release --output D:\a\1\a\s
MSBuild version 17.3.2+561848881 for .NET
  Determining projects to restore...
C:\Program Files\dotnet\sdk\6.0.408\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.EolTargetFrameworks.targets(28,5): warning NETSDK1138: The target framework 'netcoreapp2.0' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [D:\a\1\s\MyProject.csproj]
C:\Program Files\dotnet\sdk\6.0.408\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.EolTargetFrameworks.targets(28,5): warning NETSDK1138: The target framework 'netcoreapp2.0' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [D:\a\1\s\MyProject.csproj]
  All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\6.0.408\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.EolTargetFrameworks.targets(28,5): warning NETSDK1138: The target framework 'netcoreapp2.0' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [D:\a\1\s\MyProject.csproj]
  MyProject -> D:\a\1\s\bin\release\netcoreapp2.0\MyProject.dll
  You must install or update .NET to run this application.

  App: C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.mvc.razor.viewcompilation\2.0.0\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.dll
  Architecture: x64
  Framework: 'Microsoft.NETCore.App', version '2.0.0' (x64)
  .NET location: C:\Program Files\dotnet\

  The following frameworks were found:
    3.1.4 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    3.1.6 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    3.1.20 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    3.1.32 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    6.0.5 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    6.0.16 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

  Learn about framework resolution:
  https://aka.ms/dotnet/app-launch-failed

  To install missing framework, download:
  https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.0&arch=x64&rid=win10-x64
C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.mvc.razor.viewcompilation\2.0.0\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets(60,5): error MSB3073: The command ""C:\Program Files\dotnet\dotnet.exe" exec --runtimeconfig "D:\a\1\s\bin\release\netcoreapp2.0\MyProject.runtimeconfig.json" --depsfile "D:\a\1\s\bin\release\netcoreapp2.0\MyProject.deps.json" "C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.mvc.razor.viewcompilation\2.0.0\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.dll" @"obj\release\netcoreapp2.0\microsoft.aspnetcore.mvc.razor.viewcompilation.rsp"" exited with code -2147450730. [D:\a\1\s\MyProject.csproj]
##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://learn.microsoft.com/en-us/dotnet/core/tools/ and https://learn.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Dotnet command failed with non-zero exit code on the following projects : [ 'D:\\a\\1\\s\\MyProject.csproj' ]
##[section]Finishing: Publish

我直覺認為這件事跟 .NET Core 的「版本」有關係,所以我使用了 Azure DevOps Services 的 Use .NET Core task 來鎖定版本到 .NET Core SDK 2.1.202 版本,問題果然迎刃而解!

不過,此時又產生了新的問題,這次跟 Node.js 的 npm install 有關,錯誤訊息如下:

##[section]Starting: Run npm install
==============================================================================
Task         : Command Line
Description  : Run a command line with arguments
Version      : 1.1.3
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613735)
==============================================================================
##[command]npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: angular4-aspnetcore-universal@1.0.0-rc3
npm ERR! Found: typescript@3.5.1
npm ERR! node_modules/typescript
npm ERR!   typescript@"3.5.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer typescript@"^2.0.2" from @angular/compiler-cli@4.4.7
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   @angular/compiler-cli@"^4.3.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! C:\npm\cache\_logs\2023-04-24T16_13_07_080Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\npm\cache\_logs\2023-04-24T16_13_07_080Z-debug-0.log
##[error]Process completed with exit code 1.
##[section]Finishing: Run npm install

每次遇到這種問題都有種無助感,因為 npm 套件太多了,以前專案可以 npm install 但現在不能 npm install 的問題,通常都不知道從何處著手,因為 npm 的相依性實在是太複雜了!

我嘗試了好幾次,最終放棄,改往 "Node.js 版本" 的角度著手,我使用了 Azure DevOps Services 的 Node.js tool installer task 來鎖定版本到 Node 10.24.1 版本,結果卻意外的解決無法安裝套件的問題,果然跟 Node.js 版本有關係啊!DAMN!! 🔥

解決完兩個問題後,竟然還是無法建置,這次的問題出在透過 webpack 使用 TypeScript 編譯前端原始碼的時候會失敗,遇到了語法錯誤的狀況。但我確定,此專案之前都是可以順利建置的!

這個問題的錯誤訊息如下:

  env = {"prod":true}
  Hash: 9ade5e8a4f78681792545cb6150cba6e2ae1af12
  Version: webpack 3.12.0
  Child
      Hash: 9ade5e8a4f7868179254
      Time: 2962ms
          Asset    Size  Chunks             Chunk Names
      vendor.js  102 kB       0  [emitted]  vendor
  Child
      Hash: 5cb6150cba6e2ae1af12
      Time: 8792ms
          Asset    Size  Chunks                    Chunk Names
      vendor.js  953 kB       0  [emitted]  [big]  vendor
  Hash: fbecbdb58782592c67c89d45c163c8853f18f833
  Version: webpack 3.12.0
  Child
      Hash: fbecbdb58782592c67c8
      Time: 51541ms
                                Asset     Size  Chunks                    Chunk Names
      chunk.0.5e64348587bba1d6b2c1.js   236 kB       0  [emitted]
      chunk.1.16dc8689a7305d5bb15b.js  58.9 kB       1  [emitted]
      chunk.2.005c2d465098b859664a.js  96.5 kB       2  [emitted]
      chunk.3.322597bd927e10b0f370.js   121 kB       3  [emitted]
      chunk.4.9802cc1c06e9c0032952.js   134 kB       4  [emitted]
      chunk.5.cd05843bcb71d3859898.js  79.4 kB       5  [emitted]
      chunk.6.df7c53220c2814376908.js    38 kB       6  [emitted]
                       main-client.js  1.13 MB       7  [emitted]  [big]  main-client

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1351,30): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1025,21): Type expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1026,38): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1027,26): ':' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1028,30): ':' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1028,44): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1031,21): Declaration or statement expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1043,41): Type expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1043,50): '}' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1043,55): Declaration or statement expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1043,57): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1043,64): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1046,29): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1046,30): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1046,37): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1046,48): ',' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1046,55): ',' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1053,26): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1053,27): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1053,34): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1053,45): ',' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1053,52): ',' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1307,23): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1307,54): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1312,30): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1312,40): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1312,60): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1346,23): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1346,67): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1026,24): ':' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1351,40): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1351,60): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1751,16): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1756,43): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1761,30): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1842,33): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1842,66): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1844,28): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1844,49): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1845,33): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1852,30): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1938,29): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1939,56): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2000,29): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2001,56): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2001,70): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2051,54): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2093,47): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2093,67): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2443,33): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2443,67): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2444,47): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2444,59): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2444,80): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2445,65): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2448,43): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2456,30): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2581,1): Unterminated template literal.
  Child
      Hash: 9d45c163c8853f18f833
      Time: 55479ms
                                Asset     Size  Chunks                    Chunk Names
      chunk.0.b2f21d255e28e94f8e23.js   499 kB       0  [emitted]  [big]
      chunk.1.76efee8d24bd41410ffb.js   135 kB       1  [emitted]
      chunk.2.91cbeaf192806de2cb71.js   198 kB       2  [emitted]
      chunk.3.de75d67c4faa2fb1b29d.js   238 kB       3  [emitted]
      chunk.4.a12d2f0af1e786ab6f87.js   255 kB       4  [emitted]  [big]
      chunk.5.b10de4bf24cf7e1d1ae4.js   163 kB       5  [emitted]
      chunk.6.62283688d26986135af3.js  86.4 kB       6  [emitted]
                       main-server.js  2.58 MB       7  [emitted]  [big]  main-server

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1351,30): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1025,21): Type expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1026,38): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1027,26): ':' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1028,30): ':' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1028,44): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1031,21): Declaration or statement expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1043,41): Type expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1043,50): '}' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1043,55): Declaration or statement expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1043,57): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1043,64): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1046,29): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1046,30): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1046,37): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1046,48): ',' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1046,55): ',' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1053,26): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1053,27): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1053,34): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1053,45): ',' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1053,52): ',' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1307,23): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1307,54): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1312,30): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1312,40): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1312,60): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1346,23): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1346,67): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1026,24): ':' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1351,40): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1351,60): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1751,16): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1756,43): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1761,30): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1842,33): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1842,66): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1844,28): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1844,49): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1845,33): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1852,30): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1938,29): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (1939,56): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2000,29): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2001,56): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2001,70): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2051,54): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2093,47): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2093,67): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2443,33): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2443,67): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2444,47): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2444,59): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2444,80): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2445,65): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2448,43): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2456,30): ';' expected.

      ERROR in D:/a/1/s/node_modules/@types/lodash/common/object.d.ts (2581,1): Unterminated template literal.

老實說,webpack 設定檔的語法我都看的懂,但要找出編譯失敗的問題我還真不知道怎樣改起!重點是,之前是可以編譯的啊!

這個部分我也是嘗試了好久,是到很後面才想到可能跟「套件版本」有關係,畢竟錯誤發生的地方都在 @types/lodash 套件身上,可能是新版的套件無法讓舊版本的 TypeScript 工具所編譯造成的,我找到了 package.json 中的版本定義,他是這樣寫的:

"@types/lodash": "^4.14.74",

我嘗試把 ^ 刪除,鎖定版本在 4.14.74 就好,改成這樣:

"@types/lodash": "4.14.74",

結果竟然成功了,專案可以順利通過 CI 建置了!😃

心得分享

這一則簡短的是我花了好幾個小時換來的心得,以後我就知道了,為了替「未來」的你減少麻煩,我日後的 CI 都會認真考慮做出以下設定:

  1. 鎖定 SDK 版本,無論是 .NET Core / .NET 或 Node.js,總之把執行環境的版本定下來就對了!

  2. 鎖定 npm 版本,將 package-lock.json 加入版控,並改用 npm ci 還原套件,如此一來才能鎖定每個可用的套件版本!

  3. 如果特定 npm 套件出問題,可以考慮使用「固定版本」來避免無法建置專案的問題!

相關連結

留言評論