Skip to content

Inconsistency between ng serve and ng build when using Node.js built-ins #29077

Closed
@Deku-nattsu

Description

@Deku-nattsu

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

19.0.2

Description

After updating the angular cli to 19.0.4, i can no longer serve my project, the issue comes from the usage of pdfjs-dist that includes usage of nodejs build-ins. however i am able to build successfully which contradicts with the goal fc41f50

My expecation is a workaround this build blocking error (probably through the compiler configuration) and the consistency of errors between serving and build.

Minimal Reproduction

  1. create a new angular project
  2. install any library that uses nodejs build-ins in my case pdfjs-dist@4.6.82
  3. try to serve/build

here's the repo to reproduce it: https://github.com/Deku-nattsu/nodejs-build-ins-error
stackblitz: https://stackblitz.com/~/github.com/Deku-nattsu/nodejs-build-ins-error

Exception or Error

when serving:

 [ERROR] The package "url" wasn't found on the file system but is built into node. [plugin angular-browser-node-built-in]

    node_modules/pdfjs-dist/build/pdf.mjs:5666:48:
      5666 │       url = await import(/*webpackIgnore: true*/"url");
           ╵                                                 ~~~~~

✘ [ERROR] The package "fs" wasn't found on the file system but is built into node. [plugin angular-browser-node-built-in]

    node_modules/pdfjs-dist/build/pdf.mjs:5663:51:
      5663 │     const fs = await import(/*webpackIgnore: true*/"fs"),
           ╵                                                    ~~~~

✘ [ERROR] The package "http" wasn't found on the file system but is built into node. [plugin angular-browser-node-built-in]

    node_modules/pdfjs-dist/build/pdf.mjs:5664:49:
      5664 │       http = await import(/*webpackIgnore: true*/"http"),
           ╵                                                  ~~~~~~

✘ [ERROR] The package "https" wasn't found on the file system but is built into node. [plugin angular-browser-node-built-in]

    node_modules/pdfjs-dist/build/pdf.mjs:5665:50:
      5665 │       https = await import(/*webpackIgnore: true*/"https"),
           ╵                                                   ~~~~~~~

Your Environment

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 19.0.4
Node: 20.15.1
Package Manager: npm 10.7.0
OS: win32 x64

Angular: 19.0.3
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1900.4
@angular-devkit/build-angular   19.0.4
@angular-devkit/core            19.0.4
@angular-devkit/schematics      19.0.4
@angular/cli                    19.0.4
@schematics/angular             19.0.4
rxjs                            7.8.1
typescript                      5.6.3
zone.js                         0.15.0

Anything else relevant?

No response

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions