Quramy / tsuquyomi

A Vim plugin for TypeScript
http://www.vim.org/scripts/script.php?script_id=5151
1.39k stars 72 forks source link

Error: "Cannot find name 'module' #79

Open elpddev opened 8 years ago

elpddev commented 8 years ago

I get this error with angular cli latest project on every ts file.

src/app/app.component.ts|5 col 13 error| TS2304: Cannot find name 'module'.                  
node_modules/@angular/common/src/directives/ng_class.d.ts|| TS2304: Cannot find name 'Set'.
node_modules/@angular/common/src/facade/async.d.ts|| TS2304: Cannot find name 'Promise'.
node_modules/@angular/common/src/facade/async.d.ts|| TS2304: Cannot find name 'Promise'.
node_modules/@angular/common/src/facade/lang.d.ts|| TS2304: Cannot find name 'Map'.
node_modules/@angular/common/src/facade/lang.d.ts|| TS2304: Cannot find name 'Set'.
node_modules/@angular/common/src/facade/lang.d.ts|| TS2304: Cannot find name 'Map'.
node_modules/@angular/common/src/facade/promise.d.ts|| TS2304: Cannot find name 'Promise'.
node_modules/@angular/common/src/facade/promise.d.ts|| TS2304: Cannot find name 'Promise'.
node_modules/@angular/common/src/facade/promise.d.ts|| TS2304: Cannot find name 'Promise'.

Versions:

vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 16 2016 10:50:38)
~/.vim/bundle/tsuquyomi$ git log
commit 8c0cdfb818d91d3a8aa3fc8f1b038ca3bf60c9a5
Author: y-kurami <yosuke.kurami@gmail.com>
Date:   Tue Jul 12 02:20:48 2016 +0900

    Update deps version

Is there some configuration I'm missing ? On other editors like Atom it is not an issue.

bloadvenro commented 8 years ago

@elpddev Is it ok, when you're trying to compile project with tsc?

Prior99 commented 7 years ago

Did someone ever solve this? It is really so annoying, especially for Promises.

nickspoons commented 7 years ago

What does your tsconfig.json look like?

Prior99 commented 7 years ago

@nickspoons Sure, thanks for the quick response. Here you go:

$ cat tsconfig.json
{
    "compilerOptions": {
        "outDir": "./dist/",
        "sourceMap": true,
        "noImplicitAny": true,
        "module": "commonjs",
        "target": "es5",
        "jsx": "react",
        "pretty": true,
        "noUnusedParameters": true,
        "experimentalDecorators": true,
        "noUnusedLocals": true,
        "lib": ["dom", "es2017"]
    },
    "include": [
        "src/**/*.ts?",
        "config.ts",
        "typings/*"
    ]
}

It compiles fine btw.

Here are some of the dependencies I use which might be relevant:

$ cat package.json| grep type
    "lint:src": "tslint --format stylish --type-check --project tsconfig.json",
    "type": "git",
    "typescript",
    "@types/bytes": "^2.4.33",
    "@types/gravatar": "^1.4.28",
    "@types/history": "^4.5.0",
    "@types/http-status-codes": "^1.0.29",
    "@types/lowlight": "0.0.0",
    "@types/material-ui": "^0.16.44",
    "@types/node": "^7.0.5",
    "@types/ramda": "^0.0.3",
    "@types/random-seed": "^0.3.1",
    "@types/react": "^15.0.11",
    "@types/react-dom": "^0.14.19",
    "@types/react-intl": "^2.2.0",
    "@types/react-redux": "^4.4.35",
    "@types/react-router": "^3.0.4",
    "@types/react-syntax-highlighter": "0.0.1",
    "@types/react-tap-event-plugin": "0.0.30",
    "@types/reselect": "^2.0.27",
    "@types/uuid": "^2.0.29",
    "@types/whatwg-fetch": "0.0.33",
    "array.prototype.find": "^2.0.1",
    "@types/enzyme": "^2.5.39",
    "@types/fetch-mock": "^5.8.1",
    "@types/jest": "^20.0.4",
    "@types/jquery": "=2.0.45",
    "@types/jsdom": "=2.0.30",
    "@types/redux-mock-store": "0.0.7",
    "@types/sinon": "^1.16.34",
    "awesome-typescript-loader": "=3.0.8",
    "typescript": "=2.2.0",
nickspoons commented 7 years ago

What happens if you remove your "include" section from tsconfig.json, and add an "exclude" instead:

"exclude": [ "**/node_modules/*" ]

Prior99 commented 7 years ago

That helped. But why? After changing back to using include I can no longer reproduce it. Weird.

ghost commented 6 years ago

I have a similar case for which I asked a question on stackexchange. I have the messages Cannot find name 'JQuery' and Cannot find name 'crossfilter'* respectively. What does this message mean exactly? How does syntactic index keywords?

My package.json and tsconfig.json files are respectively:

{
  "compilerOptions": {
    "target": "es5",
    "sourceMap": false,
    "outDir": "./built",
    "rootDir": "src"
  },
  "include": [
    "**/*"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": true
}

and

{
  "name": "Foo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "directories": {
    "test": "test"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/crossfilter": "0.0.30",
    "@types/d3": "^4.7.0",
    "@types/dc": "0.0.23",
    "@types/jquery": "^2.0.41"
  },
  "dependencies": {
    "@types/dc": "0.0.23",
    "@types/jquery": "^2.0.41"
  }
}
noscripter commented 5 years ago

You should try install the types needed for your project by yarn install or npm install and tsserver should resolve the dependencies.