Ts-node: error TS2503: Cannot find namespace (tsc compiled, ts-node failed)

Created on 23 May 2019  Â·  7Comments  Â·  Source: TypeStrong/ts-node

Node

10.15.3

Npm

6.9.1-next.0

Typescript

3.4.5

ts-node

8.1.0

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2017",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "suppressImplicitAnyIndexErrors": true,
    "noImplicitAny": true,
    "skipLibCheck": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": false,
    "strictNullChecks": false,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist",
    "removeComments": true,
    "baseUrl": ".",
    "paths": {
      "*": ["node_modules/*"]
    }
  },
  "include": ["src/**/*"],
  "exclude": ["src/**/*.test.ts"]
}

Compiling gives me an error: error TS2503: Cannot find namespace 'Crud'.

File crud.types.ts

namespace Crud {
  export interface Foo {}
}

File using Crud, no import needed (is in the name directory)

const options: Crud.Foo = ...
needs more info

Most helpful comment

There’s a section in the README called “I can’t find types” - have you checked that?

I'm experiencing similar problem, but can't find that section in the README anymore. Can you tell me, please, where is it now?

All 7 comments

There’s a section in the README called “I can’t find types” - have you checked that?

Totally missed that, thank you!

There’s a section in the README called “I can’t find types” - have you checked that?

I'm experiencing similar problem, but can't find that section in the README anymore. Can you tell me, please, where is it now?

i am having the same problem. In all namespace it is give me error => error TS2503: Cannot find namespace.
I'm updating from angular 7 to 9

this is my package.json dependencies
"dependencies": {
"@agm/core": "1.0.0",
"@agm/js-marker-clusterer": "1.0.0",
"@angular/animations": "^9.1.9",
"@angular/cdk": "^7.3.7",
"@angular/common": "^9.1.9",
"@angular/compiler": "^9.1.9",
"@angular/core": "^9.1.9",
"@angular/forms": "^9.1.9",
"@angular/platform-browser": "^9.1.9",
"@angular/platform-browser-dynamic": "^9.1.9",
"@angular/router": "^9.1.9",
"@fortawesome/fontawesome-free": "^5.12.1",
"@ngx-translate/core": "^11.0.1",
"@ngx-translate/http-loader": "^4.0.0",
"@types/googlemaps": "^3.39.2",
"bootstrap": "^4.4.1",
"chart.js": "^2.9.3",
"core-js": "^2.6.11",
"js-marker-clusterer": "^1.0.0",
"ngx-clipboard": "^12.3.1",
"ol": "^5.3.3",
"primeflex": "^1.0.0",
"primeicons": "^1.0.0",
"primeng": "^8.0.0",
"quill": "^1.3.7",
"rxjs": "~6.5.5",
"terser": "^3.17.0",
"tslib": "^1.10.0",
"xlsx": "^0.14.3",
"zone.js": "~0.10.2"
}

"devDependencies": {
"@angular-devkit/build-angular": "~0.901.7",
"@angular/cli": "^9.1.7",
"@angular/compiler-cli": "^9.1.9",
"@angular/language-service": "^9.1.9",
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^7.6.0",
"@types/jasmine": "^3.5.3",
"@types/jasminewd2": "^2.0.8",
"@types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"cz-conventional-changelog": "^2.1.0",
"husky": "^1.3.1",
"jasmine-core": "~3.3.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^2.1.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.5.2",
"lint-staged": "^8.1.7",
"nyc": "^13.3.0",
"protractor": "^5.4.3",
"ts-node": "^8.6.2",
"tslint": "~5.12.1",
"typescript": "~3.8.3"
}

and this is my tsconfig.json

{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"downlevelIteration": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}

and this is my tsconfig.app.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"types": []
},
"files": [
"main.ts",
"polyfills.ts"
],
"include": [
"src/*/.d.ts"
]
}

someone can help me.

Remove this: "types": []

@Maxim-Mazurok still it's happen, i removed that but still happend

@lotar94 try renaming the crud.types.ts file to crud.types.d.ts, this worked for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

watzon picture watzon  Â·  3Comments

mattdell picture mattdell  Â·  4Comments

motss picture motss  Â·  4Comments

joshua-tj picture joshua-tj  Â·  3Comments

sodiumjoe picture sodiumjoe  Â·  4Comments