Skip to content

Cannot find module 'fs' #5812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sjclemmy opened this issue Nov 27, 2015 · 8 comments · Fixed by #5827
Closed

Cannot find module 'fs' #5812

sjclemmy opened this issue Nov 27, 2015 · 8 comments · Fixed by #5827
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@sjclemmy
Copy link

Possibly related to #5149
I'm getting the above error when trying to compile a node reference. I've set up all the typings correctly I believe, my IDE (webStorm) is comfortable with the module name resolution and the compiled files are correct. However the compiler is still throwing these errors for core node components.
Is this a current issue or am I missing something?

@kitsonk
Copy link
Contributor

kitsonk commented Nov 27, 2015

What is your moduleResolution compiler setting?

@sjclemmy
Copy link
Author

I wasn't aware of that flag, but I've just added it and put in 'node' as the option and I still get the error. I've used tsd to get install the typings file and referenced it directly rather than referencing the tsd.json fie.

top of 'makeModule.ts' file:

/// <reference path="typings/node/node.d.ts" />
import * as fs from "fs";

tsconfig.json file:

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true
  },
  "files": [
    "makeModule.ts"
  ]
}

@DanielRosenwasser
Copy link
Member

Whoops, misread the original issue and removed my comment.

@DanielRosenwasser
Copy link
Member

I'm not able to reproduce the issue. You're saying that you're getting issues at the command line, right? What version of TypeScript are you using? What are you typing on the command line to execute the compiler?

@DanielRosenwasser DanielRosenwasser added the Needs More Info The issue still hasn't been fully clarified label Nov 28, 2015
@sjclemmy
Copy link
Author

I've isolated the commands and created a new folder etc, and I can't reproduce the issue. Let me see if it's something to do with some other element in the ts file I've created.

@sjclemmy
Copy link
Author

Found the issue.
My script has #!/usr/local/bin/node at the top. This causes the issue.
To reproduce the issue:
There is a type file in typings/node/node.d.ts, in this case installed using command tsd install node.

problemfile.ts contains:

#!/usr/bin/env node

/// <reference path="typings/node/node.d.ts" />

import * as fs from "fs";
var currentDir = process.cwd();

and compile with tsc --module commonjs problemfile.ts

This generates the errors:

problemfile.ts(5,21): error TS2307: Cannot find module 'fs'.
problemfile.ts(6,18): error TS2304: Cannot find name 'process'.

@vladima
Copy link
Contributor

vladima commented Nov 30, 2015

this is bug - we should ignore shebang trivia similar to what we do with other kinds of trivia when processing reference comments

@daslicht
Copy link

Even tho I installed the latest node @types i get an error when tying to use :
import * as fs from "fs";

How about this one :
const config = require( __dirname+'/../../../config.json');

I tried it with :
import * as config from '/../../../config.json';
But I just get Cannot find module...

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants