"error TS2304: Cannot find name" after updating to 7.0.0
See original GitHub issueI updated ts-node from 6.2.0 to 7.0.0 and I started to get the following error:
TSError: ⨯ Unable to compile TypeScript:
src/common/atlas/atlas.constants.ts(3,27): error TS2304: Cannot find name 'Tile'.
src/common/atlas/atlas.constants.ts(6,31): error TS2304: Cannot find name 'ITileLayer'.
src/common/atlas/atlas.constants.ts(27,28): error TS2304: Cannot find name 'ITileLayer'.
at createTSError (/Users/miguel/src/later/node_modules/ts-node/src/index.ts:261:12)
at getOutput (/Users/miguel/src/later/node_modules/ts-node/src/index.ts:367:40)
at Object.compile (/Users/miguel/src/later/node_modules/ts-node/src/index.ts:557:11)
at Module.m._compile (/Users/miguel/src/later/node_modules/ts-node/src/index.ts:439:43)
at Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at require.extensions.(anonymous function) (/Users/miguel/src/later/node_modules/ts-node/src/index.ts:442:12)
at Object.nodeDevHook [as .ts] (/Users/miguel/src/later/node_modules/node-dev/lib/hook.js:61:7)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
[ERROR] 11:14:48 TSError
It looks like this version is not able to find my custom type definitions. I recently started to learn typescript so I’m not sure if what I’m doing is good practice, this is my folder structure

Y put my types inside *.d.ts files and nothing more, this worked before updating.
Not sure if this can help but here is my .tsconfig
{
"compilerOptions": {
"strict": true,
"alwaysStrict": true,
"module": "commonjs",
"moduleResolution": "node",
"types": ["node", "jest", "pixi.js", "matter-js"],
"newLine": "LF",
"outDir": "lib",
"jsx": "preserve",
"target": "es2017",
"lib": [
"es2017",
"dom"
],
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitAny": true,
"noFallthroughCasesInSwitch": true,
"experimentalDecorators": true,
"baseUrl": "./src",
"paths": {
"common/*": [
"./common/*"
],
"client/*": [
"./client/*"
],
"server/*": [
"./server/*"
]
}
},
"include": [
"src/common/**/*.ts",
"src/client/**/*.ts"
],
"exclude": [
".git",
"node_modules"
]
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:41 (23 by maintainers)
Top Results From Across the Web
TypeScript getting error TS2304: cannot find name ' require'
I am getting the error "TS2304: Cannot find name 'require' " when I attempt to transpile a simple TypeScript Node.js page. I have...
Read more >cannot find module 'protractor' or its corresponding type ...
Angular 10 error "Cannot find module '@angular/core' or its corresponding type declarations" ... error TS2304: Cannot find name 'beforeEach'.
Read more >Changelog - Cypress Documentation
0 regression where using custom reporters would cause Cypress to throw a 'Cannot find module' error. Fixes #24607; Fixed testIsolation configuration validation ...
Read more >Firebase JavaScript SDK Release Notes - Google
0 upgraded TypeScript only in the root. Fixed a bug that caused Firebase SDKs to throw an error in Firefox browsers when third-party...
Read more >Upgrading to TensorFlow.js 3.0
When using typescript<4.4 , the following error will occur. node_modules/@webgpu/types/dist/index.d.ts:587:16 - error TS2304: Cannot find name ' ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Why make a major release so quickly? I do agree that, as @weswigham says, “the build orchestrator is not part of the build it orchestrates”, but the fix is kind of on the extreme side. Why not at least try taking some useful parts out of the
tsconfig.json, if there is one?esModuleInterop,lib,typeRoots,exclude, the strictness settings, etc.Sticking to v6 for now, since I don’t want to:
tsconfig.jsonjust forts-node.ts-nodeinvocation with a--project.It’s possible that I’m in the tiny minority here, but the discussion was way too short for this change, IMO.
@blakeembrey Thank you for taking time to look into this. Decided to investigate this myself, and wow, still got some misconceptions. Everything was working, so I was sure I had it all figured out…
Indeed,
typeRootswas doing nothing. The typings were being picked up by TypeScript’s defaultinclude(mytsconfig.jsonhas only anexclude). It would work if the typings did have the right shape, buttypeRootsis for global declarations,pathsis a better fit for that. Which is conveniently omitted intsconfig.jsondocs, and is instead described in module resolutions docs.The “fix” is to put this in place of
typeRoots:And translate all typings from
typings/*.d.tstotypings/*/index.d.ts, i.e. from this:To this:
I’m choosing this approach because I always wanted my typings to look the same as what you would find on DefinitelyTyped, and now it’s possible, and it works with both
ts-nodeandtsc.I also have typings like this:
These are okay to leave as-is, since they make sense only in the context of a bundler like Webpack, and
ts-nodeshouldn’t be able to execute files which import SVGs and such. One exception is JSON, but there’s a setting for it now in TS 2.9. This way, there’s no need in involvingtypeRootsat all.I’m glad this change broke my stuff, now I have a better config and a better understanding of it, thanks.
Edit
Have fiddled around some more, and found out that
pathsworks withdeclare module 'some-npm-package'too, so if you’re in a rush, you don’t even have to do the translation part, just make sure the directory matches the module.Adding
typings/*/index.d.tstoexcludecan help with some typos/mistakes.