Domanda

It seems everyone's got the sample to work, but mine just won't...

I have nodejs 0.8.2 install in windows 7 64bit. Did a npm install -g typescript to get TypeScript support. Then I downloaded the source from TypeScript and tried the samples but I just can't get the node sample to compile. It returns the error message:

c:\..\..\typescript\bin\tsc.js:21182
           if(_fs.existsSync(path)) {
                  ^
TypeError: Object #(Object) has no method 'existsSync'
...
...

Has anyone else seen this problem?

Been looking around for hours without finding anything.

Say that I have this code:

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


import http = module("http");

var server = http.createServer(function (req, res)
{
    res.writeHead(200, { 'ContenType': 'text/plain' });
    res.end('Hello World');
});

server.listen(1337);

Typed this up in Visual 2012 express for web, which showed no error. The reference is in place, and intellisense is working fine. But when I use the command-line tool with node to compile this file, it pops the error shown further up.. I did not include _fs.existsSync in my own code.

Ok... after playing around with tsc.js and nodejs... I realized that the _fs object created from require('fs') in node engine doesn't have a function called existsSync at all...

After searching a bit more... apparently this function is now under the path module... I'll try editing tsc.js to use the path module's existsSync function instead.

È stato utile?

Soluzione

Ok... change the tsc.js to use _path.existsSync instead seem to work. But after some more fiddling around, I found the the node version on my system is still v0.6.2. Even though I tried to install v0.8.12 downloaded from the site before. After removing v0.6.2 and installed v0.8.14, now the fs module contains the target function.

I wonder why the node version on this system was stuck on 0.6.2 ~''~

Altri suggerimenti

I think the problem is because you a have a typo error in your code. Try using fs.existsSync(path). You are trying to assign a method to an object which does not exists.

fs.existsSync('path/to/file');

or fs.exists() which is synonymous with the above, only you are using a callback if connection has succeeded.

fs.exists('/path/to/file', function (exists) {
  util.debug(exists ? "it's there" : "no passwd!");
});

http://nodejs.org/api/fs.html#fs_fs_exists_path_callback

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top