0

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Is it not possible to use webpack on the backend? I am not compiling my typescript for the frontend
No. You don't need webpack for the backend! To compile for the backend use grunt or even just tsc e.g. tsc -w -p ./src
Ah, OK. That makes sense - thank you. I guess I need to work out how to compile the files into a dist dir because it seems messy all the js files being created all over the place alongside my ts files
@cubabit use --outDir

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.