【问题标题】:angular2 and typescript errorangular2和打字稿错误
【发布时间】:2017-03-12 14:05:23
【问题描述】:

我正在尝试创建一个 Angular 2 应用程序并使用hammerjs 进行触摸手势。 目前我正在尝试将来自Angular 2 的快速入门应用程序与来自Hammerjs sample 的hammerjs 应用程序结合起来。

我不断收到错误:

http://localhost:3000/npm:plugin-typescript@4.0.10/lib/plugin.js Failed to load resource: the server responded with a status of 404 (Not Found)
localhost/:33 Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/npm:plugin-typescript@4.0.10/lib/plugin.js
Error: XHR error (404 Not Found) loading http://localhost:3000/npm:plugin-typescript@4.0.10/lib/plugin.js
Error loading http://localhost:3000/npm:plugin-typescript@4.0.10/lib/plugin.js
Unable to load transpiler to transpile http://localhost:3000/app/app.component.js
Error loading http://localhost:3000/app/app.component.js

我的 systemjs.config.js 文件:

(function (global) {
  System.config({
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
transpiler: 'ts',
typescriptOptions: {
  tsconfig: true
},
meta: {
  'typescript': {
    "exports": "ts"
  }
},
paths: {
  // paths serve as alias
  'npm:': 'node_modules'
},
// map tells the System loader where to look for things
map: {
  // our app is within the app folder
  app: 'app',

  // angular bundles
  '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
  '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
  '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
  '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
  '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
  '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
  '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
  '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
  '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',

  // other libraries
  'rxjs':                       'npm:rxjs',
  'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api',
  'ts':                         'npm:plugin-typescript@4.0.10/lib/plugin.js',
  'typescript':                 'npm:typescript@2.0.2/lib/typescript.js',

},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
  app: {
    main: './app.component.js',
    defaultExtension: 'js'
  },
  rxjs: {
    defaultExtension: 'js'
  },
  'angular2-in-memory-web-api': {
    main: './index.js',
    defaultExtension: 'js'
      }
    }
   });
})(this);

我的文件夹结构:

mypackage.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.0.1",
    "zone.js": "^0.7.4"
  },
  "devDependencies": {
    "concurrently": "^3.2.0",
    "lite-server": "^2.2.2",
    "typescript": "~2.0.10",

    "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": {}
}

我安装了所有 npm install 模块。

我错过了什么?

【问题讨论】:

  • 您是否在命令行上运行了 npm install ?你的 package.json 文件的内容是什么?它没有找到这个库:npm:plugin-typescript@4.0.10/lib/plugin.js
  • 我更新了问题。我做了 npm install 并且确实有所有依赖项。顺便说一句,我的 node_modules/typescript 文件夹中没有 plugin.js。
  • 这是您缺少的库:github.com/frankwallis/plugin-typescript。这不是 typescript 库,它是第 3 方库。
  • Claies - 我不知道该插件,现在它已安装,我在使用此插件设置 System.config 时遇到问题。你能看到应该在那里设置什么吗?
  • 如果您确实需要使用缺少的插件,请到它的github仓库(github.com/frankwallis/plugin-typescript)阅读文档。如果您不需要,请在系统中删除该行。 config.js 文件,看看会发生什么。这就是插件的用途,“SystemJS 的插件,它使您能够直接 System.import TypeScript 文件。文件在浏览器中被转译,编译错误被写入控制台。”

标签: javascript angular typescript hammer.js


【解决方案1】:

您可能需要这个(来自 SystemJS 的 ypeScript 加载程序的文档):如果您使用没有 JSPM 的 SystemJS(您正在使用 npm),请为 plugin-typescript 和 typescript 添加 SystemJS 映射配置:

SystemJS.config({
  packages: {
    "ts": {
      "main": "plugin.js"
    },
    "typescript": {
      "main": "lib/typescript.js",
      "meta": {
        "lib/typescript.js": {
          "exports": "ts"
        }
      }
    }
  },
  map: {
    "ts": "path/to/plugin-typescript/lib",
    "typescript": "path/to/typescript"
  },
  transpiler: 'ts'
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    • 2017-11-07
    • 2016-08-08
    • 1970-01-01
    相关资源
    最近更新 更多