0
votes

I am trying to use TypeScript with node, socket.io and webpack.

I have set up webpack.config.js, tsconfig.json and tsd.json and downloaded the typings file for socket.io from the DefinitelyTyped repository using tsd. I have installed socket.io with npm.

When I run:

webpack

I get the following error:

ERROR in ./~/socket.io/lib/index.js
Module not found: Error: Cannot resolve module 'fs' in /private/tmp/ts-test/node_modules/socket.io/lib
 @ ./~/socket.io/lib/index.js 7:11-24

It appears webpack cannot resolve the inclusion of a module from within the node_modules directory.

My versions are:

  • node v4.2.1
  • tsd 0.6.5
  • tsc 1.7.5
  • webpack 1.12.11
  • socket.io 1.4.4

I have published a small example to this repository: https://github.com/cubabit/typescript-problems

1

1 Answers

2
votes

Error: Cannot resolve module 'fs' in /private/tmp/ts-test/node_modules/socket.io/lib

That file should not be loaded in the frontend. You are loading the backend / nodejs javascript files of NodeJS.

Socket.io comes with both the backend and frontend.

More

For a working example give http://alm.tools/ source code a go.