Error: Unable to resolve module 'module' in path /.../ rewire / lib
I am using a rewire
prior method require
in a React / Flux app to load components. But after installing I got this error:
ERROR in ./~/rewire/lib/rewire.js
Module not found: Error: Cannot resolve module 'module' in /Users/path/node_modules/rewire/lib
@ ./~/rewire/lib/rewire.js 1:13-30
ERROR in ./~/rewire/lib/rewire.js
Module not found: Error: Cannot resolve module 'fs' in /Users/path/node_modules/rewire/lib
@ ./~/rewire/lib/rewire.js 2:9-22
ERROR in ./~/rewire/lib/moduleEnv.js
Module not found: Error: Cannot resolve module 'module' in /Users/path/node_modules/rewire/lib
@ ./~/rewire/lib/moduleEnv.js 3:13-30
ERROR in ./~/rewire/lib/moduleEnv.js
Module not found: Error: Cannot resolve module 'fs' in /Users/path/node_modules/rewire/lib
@ ./~/rewire/lib/moduleEnv.js 4:9-22
While googling I found a similar problem but not the desired solution. Does anyone know what the problem or conflict is and how to resolve it?
source to share
This is a webpack issue.
Since you are trying to use rewire, I am assuming that you plan on running your tests through NodeJS and not in the browser. Otherwise check out rewire-webpack .
Rewire expects a NodeJS framework, but by default webpack targets the browser environment and as such is unaware of the standard NodeJS modules that might depend on them.
You need to set target
your webpack config property "node"
to so the webpack knows that it should treat standard NodeJS modules as external.
source to share