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 type definition file for 'node'." for 2.4.1 #16772

Closed
donaldpipowitch opened this issue Jun 27, 2017 · 43 comments
Closed

"Cannot find type definition file for 'node'." for 2.4.1 #16772

donaldpipowitch opened this issue Jun 27, 2017 · 43 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@donaldpipowitch
Copy link
Contributor

TypeScript Version: 2.4.1

Code

https://github.com/Mercateo/ws/tree/v2

Diff yarn.lock:

typescript@^2.3.4:
-  version "2.4.0"
-  resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.0.tgz#aef5a8d404beba36ad339abf079ddddfffba86dd"
+  version "2.4.1"
+  resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.1.tgz#c3ccb16ddaa0b2314de031e7e6fee89e5ba346bc"
$ yarn
$ npm run build

Expected behavior:

Compile.

Actual behavior:

ERROR in /Users/foo/Workspace/mercateo-ws/tsconfig.json
error TS2688: Cannot find type definition file for 'node'.
@ghost
Copy link

ghost commented Jun 27, 2017

Try using --traceResolution.

@andykellr
Copy link

We are having the same problem, but it only seems to surface when running mocha with --require ts-node/register. Rolling back to 2.3.4 and will watch this issue.

@sgmccli
Copy link

sgmccli commented Jun 27, 2017

Same issue here with ts-node/register. Fails to find all imported @types modules. I have reverted back to 2.3.4.

@JnelsonEmarketer
Copy link

Ditto

@johntran
Copy link

johntran commented Jun 27, 2017

I've been debugging for the past 2.5 hours. Thank you for this issue. I was going insane.

@DanielRosenwasser DanielRosenwasser added the Needs More Info The issue still hasn't been fully clarified label Jun 27, 2017
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 2.4.2 milestone Jun 27, 2017
@RobARichardson
Copy link

Having the same issue, but for several other type definition files including angular, angular-material, and more. Had to revert back to 2.3.4.

@JasonKleban
Copy link

I think this is also an issue with ts-loader. 'tsc -p .' works fine but as of this upgrade, webpack with ts-loader involved fails like this:

ts-loader: Using [email protected] and C:\Users\Jason\Repos\...\tsconfig.json
Hash: 193ab870329ba77c54cf
Version: webpack 2.5.0
Time: 18597ms
                               Asset     Size  Chunks                    Chunk Names
                              app.js  2.41 MB       0  [emitted]  [big]  main
                          app.js.map  2.88 MB       0  [emitted]         main
...
  [69] ./src/Components/Today/Today.tsx 10.6 kB {0} [built]
...
 [380] ./src/Index.tsx 7.8 kB {0} [built]
    + 368 hidden modules

ERROR in C:\Users\Jason\Repos\...\tsconfig.json
error TS2688: Cannot find type definition file for 'node'.

ERROR in C:\Users\Jason\Repos\...\tsconfig.json
error TS2688: Cannot find type definition file for 'qrcode'.

(which is kinda weird because it looks like it built everything successfully before it errors out with this??)

Rolling back to 2.3.4 and the problem is gone.

@teppeis
Copy link

teppeis commented Jun 28, 2017

similar issue: teppeis/typescript-simple#82

@lkc0987
Copy link

lkc0987 commented Jun 28, 2017

Having similar issues with type definitions. (node, jquery...)

enforced typescript version 2.4.0 using npm-shrinkwrap as a workaround

build	27-Jun-2017 19:40:29	ERROR in ./src/main/resources/static/js/modules/InfoModule.ts
build	27-Jun-2017 19:40:29	(26,45): error TS2304: Cannot find name 'require'.
build	27-Jun-2017 19:40:29	
build	27-Jun-2017 19:40:29	ERROR in ./src/main/resources/static/js/common/Helper.ts
build	27-Jun-2017 19:40:29	(4,17): error TS2503: Cannot find namespace 'Cookies'.
build	27-Jun-2017 19:40:29	
.....
build	27-Jun-2017 19:40:29	ERROR in /var/......./webapp/tsconfig-prod.json
build	27-Jun-2017 19:40:29	error TS2688: Cannot find type definition file for 'handlebars'.

@ldrick
Copy link

ldrick commented Jun 28, 2017

Having same issues with all of our type definitions, which are:

ERROR in [censored]/tsconfig.json
error TS2688: Cannot find type definition file for 'amcharts'.

ERROR in [censored]/tsconfig.json
error TS2688: Cannot find type definition file for 'fs-extra'.

ERROR in [censored]/tsconfig.json
error TS2688: Cannot find type definition file for 'handlebars'.

ERROR in [censored]/tsconfig.json
error TS2688: Cannot find type definition file for 'highlight.js'.

ERROR in [censored]/tsconfig.json
error TS2688: Cannot find type definition file for 'jasmine'.

ERROR in [censored]/tsconfig.json
error TS2688: Cannot find type definition file for 'jquery'.

ERROR in [censored]/tsconfig.json
error TS2688: Cannot find type definition file for 'lodash'.

ERROR in [censored]/tsconfig.json
error TS2688: Cannot find type definition file for 'marked'.

ERROR in [censored]/tsconfig.json
error TS2688: Cannot find type definition file for 'minimatch'.

ERROR in [censored]/tsconfig.json
error TS2688: Cannot find type definition file for 'node'.

ERROR in [censored]/tsconfig.json
error TS2688: Cannot find type definition file for 'shelljs'.

ERROR in [censored]/tsconfig.json
error TS2688: Cannot find type definition file for 'webpack-env'.

@dashmug
Copy link

dashmug commented Jun 28, 2017

Same problem here.

@skseth
Copy link

skseth commented Jun 28, 2017

I had similar problems with ts-node, but tsc -p was fine. Upgrading to v3.1.0 fixed the problem.

@sgmccli
Copy link

sgmccli commented Jun 28, 2017

@skseth bumping ts-node seems to fix the issue for me too. I was on 3.0.6 -> 3.1.0 has done the trick.

It looks like this change TypeStrong/ts-node#366 that they seem to be expecting in TypeScript 2.5 made it out early.

@donaldpipowitch
Copy link
Contributor Author

Can I summarise this?

  • Some people have this problem with ts-node. Updating to v3.1.0 works.
  • Some people have this problem with ts-loader. (FYI @johnnyreilly.)
  • Other cases...?
  • Anyone who has this problem with tsc?

@inad9300
Copy link

inad9300 commented Jun 28, 2017

I've had this problem too using webpack and ts-loader when upgrading to TypeScript 2.4.1. In my case, I start webpack with the --watch option, and it printed a bunch of "Cannot find type definition file for x" the first time. After I made a change and the watcher detected it, the errors were gone.

I've managed to fix this by modifying the tsconfig.json file to include "types": [], which as stated in the documentation:

Specify "types": [] to disable automatic inclusion of @types packages.

Keep in mind that automatic inclusion is only important if you’re using files with global declarations (as opposed to files declared as modules). If you use an import "foo" statement, for instance, TypeScript may still look through node_modules & node_modules/@types folders to find the foo package.

@feibyte
Copy link

feibyte commented Jun 28, 2017

I had this problem when upgrading to Typescript 2.4.1. I separate webpack with my project. it means that typescript has different module paths with @types file.

@tkrotoff
Copy link

IMHO, new TypeScript releases should be tested against some simple Webpack projects that use ts-loader and ts-node (and also against DefinitelyTyped type definitions) before being published on npm.

TypeScript is not just github.com/Microsoft/TypeScript anymore, it became a whole ecosystem that needs to be kept in sync and tested

@kitsonk
Copy link
Contributor

kitsonk commented Jun 28, 2017

Actually I see it as the responsibility of these downstream projects to be ready for TypeScript. vscode integrates to insiders which is published two weeks prior to the regular release of TypeScript. We in @dojo also started the work to accept 2.4 with the release of insiders. Other projects should do such integrations as well and ensure their semver is accurate. You can't expect upstream projects to test every downstream project. It is illogical. I realise it effects folks, but you should be holding these downstream projects into account instead of projecting onto the TypeScript team. The TypeScript release cycle has been very predictable lately, which makes it a heck of a lot easier for us downstream projects.

The TypeScript team already goes over most of the DefinitelyTyped and there were quite a few patches made prior to the release of 2.4, though DefinitelyTyped is a community project.

@inad9300
Copy link

It is not illogical. Rust does this: with every release of the language, they make sure that all the projects in their package manager still compile. This feature makes the language very robust and trustworthy.

I'm not saying this is the approach to follow by TypeScript, but certainly including some common setups among the tests would make troubleshooting backwards-incompatible problems much easier. It's just a matter of being able to provide an extensive breaking changes list.

@johnnyreilly
Copy link

Just made a tweak to ts-loader which seems to resolve the issue. Thought it was probably worth sharing here for any other project maintainers who've been bitten: TypeStrong/ts-loader#566

I'm planning to release this as soon as I get a moment. FWIW I only heard about this today thanks to @donaldpipowitch helpful mention of me in this issue.

@kitsonk
Copy link
Contributor

kitsonk commented Jun 28, 2017

they make sure that all the projects in their package manager still compile

What do they do when it doesn't?

@inad9300
Copy link

inad9300 commented Jun 28, 2017

For the moment they just promise backwards compatibility.

(I must clarify that I'm not into Rust at all. I think it's a language with very interesting ideas and heard some talks on it and know a bit about its syntax, but that's about it.)

@kitsonk
Copy link
Contributor

kitsonk commented Jun 28, 2017

For the moment they just promise backwards compatibility.

Well, TypeScript doesn't between minor revisions, just patch revisions. So just making sure everything everywhere compiles wouldn't be valid.

@ghost
Copy link

ghost commented Jun 28, 2017

2.4.0 was on June 6 and 2.4.1 was on June 27. I don"t see any major changes to module resolution in that span. More likely something about the way we deal with the host in the services layer changed.

It would nice to have a simple reproducible example that I could test out on the different TypeScript versions in that short time span to try and find out what happened. I can't reproduce this with just /// <reference types="node" /> in a file run by ts-node. Nor with require("ts-node/register"); require("./a.ts");.

The only releases in that span were:

2.4.0
2.5.0-dev.20170613
2.5.0-dev.20170614
2.5.0-dev.20170615
2.5.0-dev.20170616
2.5.0-dev.20170617
2.5.0-dev.20170618
2.5.0-dev.20170619
2.5.0-dev.20170621
2.5.0-dev.20170622
2.5.0-dev.20170623
2.5.0-dev.20170624
2.5.0-dev.20170625
2.5.0-dev.20170626
2.5.0-dev.20170627
2.4.1

@samwx
Copy link

samwx commented Jun 28, 2017

Watching this... Have the same issue with @types/angular, using ts-loader with webpack

@dashmug
Copy link

dashmug commented Jun 28, 2017

My project is using Node + Typescript + Webpack + ts-loader + ts-node and I'm getting this problem when I updated to v2.4.1.

I fixed mine by switching to awesome-typescript-loader. Done. :-) No more problems.

I can still use ts-node with no problems.

@rbuckton rbuckton added External Relates to another program, environment, or user action which we cannot control. and removed Needs More Info The issue still hasn't been fully clarified labels Jun 28, 2017
@donaldpipowitch
Copy link
Contributor Author

Thank you all for solving this.

@samwx
Copy link

samwx commented Jun 28, 2017

@rbuckton Updated typescript to 2.4.1 and ts-loader to 2.2.1 and still the same =/

error TS6137: Cannot import type declaration files. Consider importing 'angular' instead of '@types/angular'.

The same project works fine on [email protected].

@stephen
Copy link

stephen commented Jun 28, 2017

@samwx - I think this is a separate, unrelated change: #16472

@samwx
Copy link

samwx commented Jun 28, 2017

@stephen Wow, that's true. Seems that typescript not supports imports like @types/... anymore. Thank you!

@virtustilus
Copy link

Reverted typescript from version 2.4.1 to 2.2.2 in package.json:
"typescript": "2.2.2",
and works fine now

@sluukkonen
Copy link

For what it's worth, upgrading ts-node to the latest version seems to fix this issue for me.

@serbanghita
Copy link

serbanghita commented Sep 20, 2017

For TypeScript 2.4.2 if you already have some custom "typeRoots": [ ... ] defined into your tsconfig.json and in your package.json you also are including "@types/node" and you work with the standard node functions like require, you will receive the error: Cannot find type definition file for 'node'.

You need to add ./node_modules/@types/ to your typeRoots array! see docs

Backstory: I had this problem because I use WebStorm IDE which uses tsc to compile the project, and webpack to compile it separately. Suddenly after removing some 3rd party node packages that I had I started having the above error. Now it's all good again.

@vinz243
Copy link

vinz243 commented Sep 26, 2017

@serbanghita you are the MVP here. Just note that the ./node_modules/@types/is relative to the directory where the tsconfig.json file is

@bennycode
Copy link
Contributor

I have a TypeScript app which imports another TypeScript app and I am receiving error TS2688: Cannot find type definition file for 'node'. from my imported module:

ode_modules/wire-webapp-cryptobox/dist/typings/wire-webapp-cryptobox.d.ts(18,23): error TS2688: Cannot find type definition file for 'node'.

I checked wire-webapp-cryptobox.d.ts(18,23) and it's this statement:
/// <reference types="node" />

The config of "wire-webapp-cryptobox.d.ts" looks as follows:

{
  "compilerOptions": {
    "declaration": false,
    "lib": ["es7", "dom"],
    "module": "commonjs",
    "moduleResolution": "node",
    "noEmitOnError": true,
    "noImplicitAny": false,
    "noImplicitReturns": true,
    "removeComments": true,
    "sourceMap": false,
    "target": "es5"
  },
  "exclude": [
    "bower_components",
    "node_modules",
    "typings/browser",
    "typings/browser.d.ts"
  ]
}

Can you tell me where I need to set typeRoots to fix the error?

@ghost
Copy link

ghost commented Sep 27, 2017

@bennyn TypeScript won't be looking at any tsconfig.json in your node_modules -- it will just use your own. Try checking the output of --traceResolution to see where it's looking. It should look in your node_modules for the dependency, but it's possible that your own tsconfig.json changed this behavior.

@Thaina
Copy link

Thaina commented Jan 22, 2018

I got this error with javascript triple slash reference too

image

I try to reference the global node module. Is it not possible?

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests