I have installed proxyquire and my ajax.test.tsx file contains the following code, just 2 lines
import * as proxyquire from 'proxyquire';
proxyquire.noCallThru();
My webpack code is the following
module.exports = {
entry: {
"book.service": './src/book.service.ts',
"ajax.test": './src/ajax.test.tsx'
},
output: {
filename: "[name].js",
path: __dirname + "/dist"
},
devtool: "source-map",
watch: true,
resolve: {
extensions: [".tsx", ".tsx", ".js", ".json", ".ts", '.d.ts']
},
module: {
rules: [
{ test: /\.tsx?$/, loader: "awesome-typescript-loader" },
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
]
},
externals: {
'react/lib/ExecutionEnvironment': true,
'react/addons': true,
'react/lib/ReactContext': 'window'
}
};
I've installed proxyquire & @types/proxyquire. When I run the webpack command it throws up the following error
WARNING in ./~/proxyquire/lib/proxyquire.js
require.extensions is not supported by webpack. Use a loader instead.
@ ./~/proxyquire/index.js 3:17-44
@ ./src/ajax.test.tsx
ERROR in ./~/proxyquire/lib/proxyquire.js
Module not found: Error: Can't resolve 'module' in '***\node_modules\pr
oxyquire\lib'
proxyquire is not compatible with webpack - https://github.com/thlorenz/proxyquire/issues/62
Problem
Proxyquire uses require.extensions which is not supported by webpack.
Alternatives
inject loader
babel-plugin-rewire
Proxyquire is built for "node.js module system", not the webpack's one. You have to use something compatible with "frontend" - inject-loader or webpack-rewire.
If you don't respect the simplicity of *-loaders - you can try rewiremock. It has proxyquire-like syntax and can work both in node.js and webpack environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With