Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
Deku-nattsu opened this issue Dec 6, 2024 · 5 comments · Fixed by #29090
Closed
1 task done

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

Deku-nattsu opened this issue Dec 6, 2024 · 5 comments · Fixed by #29090

Comments

@Deku-nattsu
Copy link

Deku-nattsu commented Dec 6, 2024

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

@pumano
Copy link

pumano commented Dec 6, 2024

got same problems with falso library after commit landed to 19.0.4. I create issue: ngneat/falso#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

@isoroka-plana
Copy link

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.

@eoussama
Copy link

eoussama commented Dec 8, 2024

bump

@ngadceser
Copy link

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

@Deku-nattsu
Copy link
Author

@alan-agius4 Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants