d.ts文件找不到模块'rxjs / Observable'

时间:2017-11-15 16:29:32

标签: angular visual-studio-2015 asp.net-web-api2 rxjs

我是Angular2 / 4的新手,我正在尝试构建一个更新SQL表的WebAPI。问题是,当我在Visual Studio 2015中运行Build函数时,我得到错误代码TS2307“找不到每个”d.ts“文件的模块'rxjs / Observable'。当我点击错误时,它会将我发送到指定文件中的Import语句,错误位于“@ rxjs / Observable”部分下。

我已经找了几个小时试图找到一个解决方案而没有找到一个符合情况的解决方案,所以如果我复制一些东西请在评论中删除一个链接,这样我就可以查看了。

如果您还需要其他任何文件,请告诉我们。先感谢您。

以下是来自VS15的错误中的一些(我可以在屏幕截图中看到的数量): error Screen Shot 这是我的Package.json文件:

   {
     "version": "1.0.0",
     "name": "asp.net",
     "private": true,
     "scripts": {
           "build": "webpack",
           "start": "static ."
           },
     "dependencies": {
           "@angular/core": "2.4.0",
           "@angular/common": "2.4.0",
           "@angular/compiler": "2.4.0",
           "@angular/platform-browser": "2.4.0",
           "@angular/platform-browser-dynamic": "2.4.0",
           "core-js": "^2.4.1",
           "zone.js": "^0.8.4",
           "rxjs": "^5.2.0",
           "reflect-metadata": "^0.1.10"
           },
     "devDependencies": {
          "gulp": "^3.9.1",
          "gulp-exec": "^2.1.3",
          "awesome-typescript-loader": "^3.1.2",
          "typings": "^2.1.0",
          "webpack": "^3.8.1",
          "ng2-bs3-modal": "0.10.4"
          }
      }

这是我的tsconfig.json

  {
   "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "lib": [ "es2015", "dom" ],
        "noImplicitAny": true,
        "suppressImplicitAnyIndexErrors": true
        }
   }

更新:1 我通过并降低了package.json文件中的角度版本号,如上所示。然后从项目中删除node_module并重新启动VS15。然后我恢复了包,找到了更多的错误等待。

new Errors 所以我希望新一批错误有助于解决问题......

2 个答案:

答案 0 :(得分:2)

根据@yms的建议,我找到了Angular2.4的Quickstart文件,并将package.json,tsconfig.jason和systemjs.config.js复制到解决方案中。然后我读了ReadMe文件,指出你必须从现在开始使用angular / cli ..所以我尝试用命令安装它:

npm install -g @angular/cli

我的错误我被缩减为“错误扩展”错误,这是通过将typescript版本推送到“^ 2.4.0”并将rxjs版本推送到package.json文件中的“5.4.2”然后恢复包。

所以这是我的工作Package.json:

{
"name": "angular-quickstart",
"version": "1.0.0",
"description": "QuickStart package.json from the documentation, supplemented 
with testing support",
"scripts": {
  "build": "tsc -p src/",
  "build:watch": "tsc -p src/ -w",
  "build:e2e": "tsc -p e2e/",
  "serve": "lite-server -c=bs-config.json",
  "serve:e2e": "lite-server -c=bs-config.e2e.json",
  "prestart": "npm run build",
  "start": "concurrently \"npm run build:watch\" \"npm run serve\"",
  "pree2e": "npm run build:e2e",
  "e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-
   others --success first",
  "preprotractor": "webdriver-manager update",
  "protractor": "protractor protractor.config.js",
  "pretest": "npm run build",
  "test": "concurrently \"npm run build:watch\" \"karma start 
  karma.conf.js\"",
  "pretest:once": "npm run build",
  "test:once": "karma start karma.conf.js --single-run",
  "lint": "tslint ./src/**/*.ts -t verbose"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
  "@angular/common": "~2.4.0",
  "@angular/compiler": "~2.4.0",
  "@angular/core": "~2.4.0",
  "@angular/forms": "~2.4.0",
  "@angular/http": "~2.4.0",
  "@angular/platform-browser": "~2.4.0",
  "@angular/platform-browser-dynamic": "~2.4.0",
  "@angular/router": "~3.4.0",
  "angular-in-memory-web-api": "~0.2.4",
  "systemjs": "0.19.40",
  "core-js": "^2.4.1",
  "rxjs": "5.4.2",
  "zone.js": "^0.7.4"
},
"devDependencies": {
  "concurrently": "^3.2.0",
  "lite-server": "^2.2.2",
  "typescript": "^2.4.0",
  "canonical-path": "0.0.2",
  "tslint": "^3.15.1",
  "lodash": "^4.16.4",
  "jasmine-core": "~2.4.1",
  "karma": "^1.3.0",
  "karma-chrome-launcher": "^2.0.0",
  "karma-cli": "^1.0.1",
  "karma-jasmine": "^1.0.2",
  "karma-jasmine-html-reporter": "^0.2.2",
  "protractor": "~4.0.14",
  "rimraf": "^2.5.4",
  "@types/node": "^6.0.46",
  "@types/jasmine": "2.5.36"
},
"repository": {}
}

答案 1 :(得分:2)

对于MAC我用以下方法解决了这个问题:

sudo npm install -g --unsafe-perm --verbose @angular/cli