Skip to content

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

Closed

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 [email protected]
  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

Activity

  1. self-assigned this
    on Dec 6, 2024
  2. pumano commented on Dec 6, 2024

    @pumano

    got same problems with falso library after commit landed to 19.0.4. I create issue: https://github.com/ngneat/falso/issues/386

    Looks like seedrandom library under the hood properly handle what to use, for nodejs uses require('crypto') while in browser use window global.crypto

  3. isoroka-plana commented on Dec 8, 2024

    @isoroka-plana

    I also started getting this issue after updating to 19.0.4 from Angular 18.

    X [ERROR]
    The package "util" wasn't found on the file system but is built into node. [plugin angular-browser-node-built-in]
        node_modules/idmission-web-sdk/dist/sdk2.esm.js:6447:24:
          6447 │     this.util = require('util');
               ╵                         ~~~~~~
    X [ERROR] The package "fs" wasn't found on the file system but is built into node.
    [plugin angular-browser-node-built-in]
        node_modules/@tensorflow/tfjs-data/dist/sources/file_data_source.js:43:25:
          43 │       const fs = require('fs');
             ╵                          ~~~~
    X [ERROR] The package "string_decoder" wasn't found on the file system but is built into node.
    [plugin angular-browser-node-built-in]
        node_modules/@tensorflow/tfjs-data/dist/util/deep_map.js:217:16:
          217 │     } = require('string_decoder');
              ╵                 ~~~~~~~~~~~~~~~~
    X [ERROR] The package "crypto" wasn't found on the file system but is built into node. [plugin angular-browser-node-built-in]
        node_modules/seedrandom/seedrandom.js:265:27:
          265 │       nodecrypto = require('crypto');
    

    It used to work without any issues before and I inspected the code of these packages they all check what environment they are running in before running those require calls so the build shouldn't try to attempt to bundle them for the browser.
    I am using @angular-devkit/build-angular:browser-esbuild.
    I can confirm this issue is gone when downgrading to 19.0.3.

  4. eoussama commented on Dec 8, 2024

    @eoussama

    bump

  5. ngadceser commented on Dec 9, 2024

    @ngadceser

    "only 19.0.4 --- I'm currently just observing since the same error occurred with nodecrypto = require('crypto'); above."

  6. added 3 commits that reference this issue on Dec 9, 2024
    44356e7
    3344b6f
    fc553c1
  7. added a commit that references this issue on Dec 9, 2024
    28bdbeb
  8. Deku-nattsu commented on Dec 9, 2024

    @Deku-nattsu
    ContributorAuthor

    @alan-agius4 Thanks :)

  9. angular-automatic-lock-bot commented on Jan 12, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  10. locked and limited conversation to collaborators on Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions