I'm a new dev but have a few projects under my belt. I'm stuck on a peculiar issue and I don't know where to start looking for a solution. Whenever I try to run "npm run build-dev", I get 38 error messages such as:
ERROR in ./src/index.js 1:13-28 Module not found: Error: Can't resolve 'path' in '/Users/******/src'
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 }
However, my index.js has only one line:
const express = require('express');
Did I add anything in package.json or webpack.dev.js that could create dozens of can't resolve error messages? I'm quite confused as I can't initialize the project.
Thank you very much for your help, Matt
package.json
{
*******
"scripts": {
"start": "node dist/bundle.js",
"build-dev": "webpack --config webpack.dev.js",
"build-prod": "webpack --config webpack.prod.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "",
"description": "",
"dependencies": {
"axios": "^0.27.2",
"dotenv": "^16.0.2",
"express": "^4.18.1"
},
"devDependencies": {
"@types/node": "^18.7.18",
"babel-loader": "^8.2.5",
"clean-webpack-plugin": "^4.0.0",
"dotenv-webpack": "^8.0.1",
"ts-loader": "^9.4.0",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.11.1"
}
}
webpack.dev.js
const webpack = require('webpack');
const path = require('path');
const Dotenv = require('dotenv-webpack');
module.exports = {
entry: './src/index.js',
mode: 'development',
/*resolve: {
extensions: [".ts", ".tsx", ".js"]
},*/
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader"
}
]
},
plugins: [
new Dotenv()
]
};