Skip to content
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

Cannot find name 'console'. (only server side) #246

Closed
hongbo-miao opened this issue Apr 25, 2016 · 14 comments
Closed

Cannot find name 'console'. (only server side) #246

hongbo-miao opened this issue Apr 25, 2016 · 14 comments

Comments

@hongbo-miao
Copy link
Contributor

I am using Angular2-Meteor, TypeScript. (Meteor version 1.3.2.4)

When I use console.log('test'); on the server side, it is working well.

However, I got this warning in my terminal:

Cannot find name 'console'.

The code for server side is very simple:

import { Meteor } from 'meteor/meteor';
Meteor.startup(() => {
    console.log('I am server');
});

I made a reproduction for this issue here.

@hongbo-miao hongbo-miao changed the title Cannot find name 'console'. Cannot find name 'console'. (only server side) Apr 25, 2016
@hongbo-miao
Copy link
Contributor Author

Originally asked on Stack Overflow.

@derekkite
Copy link

I get the same error with FileReader, both on the client and server. It seems to not know javascript library names.

The code works just fine, these errors are in the build process.

@barbatus
Copy link
Collaborator

You will need to install NodeJS typings, i.e,
go to the server folder and run typings install node --ambient there.

@hongbo-miao
Copy link
Contributor Author

hongbo-miao commented Apr 26, 2016

@barbatus thanks, I just tried typings install node --ambient, but still does not work.

@MilosStanic
Copy link

didn't work for me, either.

@denodaeus
Copy link

Also didn't work from me, I think it must have something to do with the barbatus:typescript library and how it addresses typings -- see that stack overflow post @hongbo-miao linked to.

@denodaeus
Copy link

Also to note, it seems if we eagerly load code (put in /client and /server folders), the console log warnings from the typescript compiler go away for us. It's only when we lazily load (put everything in the imports directory, as recommended by the Meteor 1.3 meteor guide), that we actually get these warnings.

That makes me think it has something to do with packaging with meteor and what's happening converting the typescript into JS. It feels like the lazily loaded case is missing some stuff, specifically the typings as defined in that stack overflow post above, specifically: https://basarat.gitbooks.io/typescript/content/docs/types/lib.d.ts.html

@twastvedt
Copy link

@denodaeus Maybe it's something different, but I've been seeing this issue with code in a /server folder as well:

server/main.ts (78, 4): Cannot find name 'console'.

@denodaeus
Copy link

Just throwing it out here, you can make this temporarily go away (the typescript compiler warnings) by throwing this into a custom typing .d.ts:

export declare var console: any;

or just declare the var inside your class files.

A work around if you want the warnings to go away, but hopefully these guys get to the root cause of the problem.

@derekkite
Copy link

Installing node@4.0.0 (DefinitelyTyped)...

Seemed to get rid of the errors on the browser part of the build, but the server still gives errors.

@barbatus
Copy link
Collaborator

The issue is in that TypeScript package uses lib.core.ts default lib on the server side which doesn't have definitions for console. NodeJS definitions from other side as now defines console in the global scope only (i.e. global.console) (see for example typed-typings/env-node#1).

So, I just created a meteor typings repo https://github.com/barbatus/meteor-typings with more or less right structure, which will be hopefully added to the typings registry (https://github.com/typings/registry). In that way we have more control over structure of the definitions. For now you could try:
(Note: it's for Meteor 1.3 only)

typings install github:barbatus/meteor-typings/meteor/1.3#849703d4981a0362700062ca72c954119e55b248 --ambient

@dagatsoin
Copy link

dagatsoin commented Apr 30, 2016

Not using Angular but React and it perfectly works too thx to @barbatus file.

@barbatus
Copy link
Collaborator

barbatus commented May 2, 2016

It's added to the registry. Install by: typings install registry:env/meteor --ambient

@denodaeus
Copy link

@barbatus Is there a reason to create a separate meteor typings repo?

There was some work done here: https://github.com/meteor-typescript/meteor-typescript-libs

That also includes typings for a lot of the meteor modules that we would use (for example: aldeed:simple-schema)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants