How do i solve web pack 5 polyfills error in angular 19

Discussão em 'Angular' iniciado por Zayno lane, Fevereiro 14, 2025.

  1. Zayno lane

    Zayno lane Guest

    I'm getting a polyfills error when trying to run ngserve:


    ./node_modules/serve-static/index.js:18:14-37 - Error: Module not found: Error: Can't resolve 'path' in '/Users/zwork07/Documents/AngularTuts/E-Mag/node_modules/serve-static'```


    BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.


    If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") } - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false }```


    the many steps i took are: npm i --save-dev webpack npm i path-browserify --save ppm i node-polyfill-webpack-plugin i have made a web pack.config.js in my root folder with this config: const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
    ​

    Other rules...
    plugins: [
    new NodePolyfillPlugin(),resolve.fallback: { "path": require.resolve("path-browserify") }
    ],
    };```

    then i changed the angular.json to:
    ```"build": {
    "builder": "@angular-devkit/build-angular:browser",
    "options": {
    "outputPath": "dist/e-mag",
    "index": "src/index.html",
    "main": "src/main.ts",
    "polyfills": ["zone.js"],```

    but it still dont work pls help me!

    Continue reading...

Compartilhe esta Página