Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack - NodeJS - Module not found: Error: Can't resolve 'fs'

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
like image 490
Senthil Kumar NH Avatar asked Aug 21 '18 10:08

Senthil Kumar NH


2 Answers

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

like image 72
Senthil Kumar NH Avatar answered Nov 07 '22 17:11

Senthil Kumar NH


Simply add this to your webpack config file:

const webpackConfig = {
  target: 'node'
};
module.exports = webpackConfig;
like image 2
Daniel Danielecki Avatar answered Nov 07 '22 18:11

Daniel Danielecki