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
1 Answer
Reset to default 0I 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.