7

I am getting following error, when build nodejs project with webpack.

ERROR in ./node_modules/mime/mime.js
Module not found: Error: Can't resolve 'fs' in 'C:\Sample\node-ts-sample\node_modules\mime'
 @ ./node_modules/mime/mime.js 2:9-22
 @ ./node_modules/send/index.js
 @ ./node_modules/express/lib/response.js
 @ ./node_modules/express/lib/express.js
 @ ./node_modules/express/index.js
 @ ./src/server.ts
 @ ./src/index.ts
Senthil Kumar NH
  • 431
  • 1
  • 5
  • 13
  • Possible duplicate of [Module not found: Error: Can't resolve 'fs'](https://stackoverflow.com/questions/40950176/module-not-found-error-cant-resolve-fs) – Saeed Zhiany Aug 21 '18 at 10:44

2 Answers2

26

It was a node application. Added a following node in webpack config solved my issue

 target:'node',

I refereed the article at https://jlongster.com/Backend-Apps-with-Webpack--Part-I

Senthil Kumar NH
  • 431
  • 1
  • 5
  • 13
2

Simply add this to your webpack config file:

const webpackConfig = {
  target: 'node'
};
module.exports = webpackConfig;
Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94