Error: "[plugin angular-browser-node-built-in] The package 'crypto' wasn't found on the file...

Discussão em 'Angular' iniciado por rami-sf, Dezembro 11, 2024.

  1. rami-sf

    rami-sf Guest

    I recently updated my Angular project to version 19, and now I’m encountering the following error when building or serving the application:

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

    node_modules/crypto-js/core.js:50:25:
    50 │ crypto = require('crypto');
    ╵ ~~~~~~~~


    I’m using the crypto-js library along with secure-web-storage to handle encrypted local storage in the browser. Here’s how I import and use these libraries in my StorageService:

    import sha256 from 'crypto-js/sha256';
    import aes from 'crypto-js/aes';
    import Utf8 from 'crypto-js/enc-utf8';


    I’ve added the following configurations to try resolving the issue:

    1- angular.json:
    "allowedCommonJsDependencies": [
    "secure-web-storage",
    "crypto-js",
    "crypto"
    ]


    2- tsconfig.json:

    "paths": {
    "crypto": ["./node_modules/crypto-js"]
    }

    Continue reading...

Compartilhe esta Página