dev-server keeps stale code of a linked (`file:`) library after `ng-packagr --watch` rebuilds it (rebuild reported, restart required)

Đang mở
#34,728 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Lĩnh vực
build-system, devtools

Hướng nghiên cứu

Start with the linked reproduction and inspect how ng serve resolves and caches the linked library’s libreria.mjs while its source map changes. Compare the resolved file path and rebuilt bundle after ng-packagr --watch updates the library. Done means the app bundle contains and runs the new code without restarting ng serve.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area: @angular/build
Command

serve

Is this a regression?
  • Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was

No response

Description

In a workspace with an application and a separate Angular library linked with a file: dependency, rebuilding the library in watch mode makes ng serve print "Application bundle generation complete", but the application bundle (main.js) still contains the previous compiled code of the library. The new code only appears after stopping and restarting ng serve.

The source map embedded in the same main.js already contains the new library source (sourcesContent), while the code is the old one. So the updated .map file seems to be re-read, but the content of libreria.mjs is reused from a previous build.

I could not determine whether this is the in-memory load cache, the file watcher, or something else.

Minimal Reproduction

Setup

  • Windows, project and library in sibling folders (D:\...\proyecto-22 and D:\...\libreria-22).

  • Library built with ng build libreria --watch --configuration development (ng-packagr).

  • App package.json: "libreria": "file:../libreria-22/dist/libreria" (npm install-links=false, so node_modules/libreria is a Junction to libreria-22\dist\libreria).

  • preserveSymlinks is not set (enabling it is not an option for me: the library sources then resolve under the app's folder and breakpoints in the library do not bind in VS Code).

  • angular.json of the app:

    "build": {
      "configurations": {
        "development": {
          "optimization": false,
          "extractLicenses": false,
          "sourceMap": { "scripts": true, "styles": true, "vendor": true }
        }
      }
    },
    "serve": {
      "options": {
        "poll": 1000,
        "prebundle": { "exclude": ["libreria"] }
      }
    }
    
  • Angular CLI cache enabled (default).

Steps to reproduce

  1. Create the app and a library (ng new, ng generate library libreria), and build the library once into dist/libreria.
  2. In the app, add "libreria": "file:../libreria-22/dist/libreria" and run npm install.
  3. In the library, create a service with a method containing console.log('v1'), and call it from the app's root component.
  4. Run ng build libreria --watch --configuration development in the library, and ng serve in the app.
  5. Change the log in the library service to console.log('v2') and wait until ng-packagr finishes.

Expected: the dev-server rebuilds and the app runs v2.

Actual: the terminal prints "Application bundle generation complete" but the app still runs v1. Searching main.js shows the old code:

// ../libreria-22/dist/libreria/fesm2022/libreria.mjs
...
console.log("v1");   // old code

while the embedded source map has the new source:

sourcesContent: "... console.log('v2'); ..."

dist/libreria/fesm2022/libreria.mjs on disk does contain the new code. Stopping and restarting ng serve fixes it.

Things I tried without success

  • poll: 1000 in serve.options (with restart).
  • Deleting .angular/cache and restarting (works until the next library change).
  • prebundle.exclude with the package name.
  • Starting from a shell with the drive letter in uppercase (D:) instead of lowercase. <remove this line if you did not launch ng serve from that shell>
Minimum Reproduction

https://github.com/LuisEscamillaMartin/repro-linked-lib-stale

Exception or Error
No error. The build reports success.
Your Environment
Angular CLI       : 22.2.5
Node.js           : 24.21.0
Package Manager   : npm 11.19.0
Operating System  : win32 x64
Anything else relevant?

Without preserveSymlinks, the library is bundled into main.js from its real path (../libreria-22/dist/libreria/fesm2022/libreria.mjs), outside node_modules.

Ngôn ngữ chính
TypeScript
Star
27k
Fork
11.8k
Merge trung bình
1 ngày 2 giờ
Pull request đã merge (30 ngày)
225

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của angular/angular-cli

Tất cả issue của angular/angular-cli

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.