Webpack and TypeScript: Cannot resolve module 'child_process' in node.d.ts Webpack and TypeScript: Cannot resolve module 'child_process' in node.d.ts reactjs reactjs

Webpack and TypeScript: Cannot resolve module 'child_process' in node.d.ts


All you're missing is a key target: 'node'.

This makes sure that the environment you are targeting is Node.js and not the browser, and will therefore ignore native dependencies.

Final Config:

module.exports = {    entry: './ui/index.ts',    target: 'node',    output: {        path: __dirname + '/build-ui',        filename: 'app.js',        publicPath: 'http://localhost:8090/assets'    },    module: {        loaders: [            {                test: /\.jsx$/,                loader: 'jsx-loader?insertPragma=React.DOM&harmony'            },            {                test: /\.css$/,                loader: "style-loader!css-loader"            },            {                test: /\.scss$/,                loader: "style-loader!css-loader!sass-loader"            },            {                test: /\.(png|jpg)$/,                loader: 'url-loader?limit=8192'            },            {                test: /\.ts$/,                loader: 'awesome-typescript-loader'            }        ]    },    resolve: {        extensions: ['', '.js', '.jsx', '.ts']    }};


You could consider using a different webpack TypeScript loader. I know a few had issues with node stuff. There are also a couple starter kits that may help out.

Disclaimer: I'm the maintainer of ts-loader.


Try creating a tsconfig.json file.

For example, as you are using awesome-typescript-loader this should work:

{  "compilerOptions": {    "target": "es5",    "module": "commonjs",    "emitDecoratorMetadata": true,    "experimentalDecorators": true,    "sourceMap": true,    "noEmitHelpers": true  },  "exclude": [    "node_modules"  ],  "awesomeTypescriptLoaderOptions": {    "forkChecker": true  },  "compileOnSave": false,  "buildOnSave": false,  "atom": { "rewriteTsconfig": false }}