最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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!

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!
Share Improve this question asked Feb 14 at 15:59 Zayno laneZayno lane 516 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I found the culprit: I injected the wrong Router, namely the express Router instead of the @angular Router. They have the same name in the autocomplete of VSC, so you can easily misstep.

发布评论

评论列表(0)

  1. 暂无评论