【问题标题】:Angular2-quickstart not loading, no errorsAngular2-quickstart 未加载,没有错误
【发布时间】:2016-10-30 05:51:09
【问题描述】:

我遵循Angular.io's typescript 教程到 T - 所有代码与底部显示的相同,以及文件结构。

当我使用npm start 启动服务器时,日志显示:

 tsc && concurrently "npm run tsc:w" "npm run lite"

  [0]
  [0] > angular2-quickstart@1.0.0 tsc:w /Users/jr/angular2-quickstart
  [0] > tsc -w
  [0]
  [1]
  [1] > angular2-quickstart@1.0.0 lite /Users/jr/angular2-quickstart
  [1] > lite-server
  [1]
  [1] Did not detect a `bs-config.json` or `bs-config.js` override file. Using  lite-   server defaults...
  [1] ** browser-sync config **
  [1] { injectChanges: false,
  [1]   files: [ './**/*.{html,htm,css,js}' ],
  [1]   watchOptions: { ignored: 'node_modules' },
  [1]   server: { baseDir: './', middleware: [ [Function], [Function] ] } }
  [1] [BS] Access URLs:
  [1]  --------------------------------------
  [1]        Local: http://localhost:3000
  [1]     External: http://192.168.0.181:3000
  [1]  --------------------------------------
  [1]           UI: http://localhost:3001
  [1]  UI External: http://192.168.0.181:3001
  [1]  --------------------------------------
  [1] [BS] Serving files from: ./
  [1] [BS] Watching files...
  [0] 10:21:10 PM - Compilation complete. Watching for file changes.
  [1] [BS] File changed: app/app.component.js
  [1] [BS] File changed: app/main.js

html 页面没有显示任何内容,并且控制台给出了 500 内部错误。进行 NPM 安装时,底部没有错误,但是当我执行 npm ls 时,我得到:

npm ERR! peer dep missing: @angular/core@2.0.0-rc.2, required by angular2-in-memory-web-api@0.0.12
npm ERR! peer dep missing: @angular/http@2.0.0-rc.2, required by angular2-in-memory-web-api@0.0.12
npm ERR! peer dep missing: reflect-metadata@0.1.2, required by angular2@2.0.0-beta.17
npm ERR! peer dep missing: es6-shim@^0.35.0, required by angular2@2.0.0-beta.17
npm ERR! extraneous: angular2@2.0.0-beta.17 /Users/jr/angular2-quickstart/node_modules/angular2

在过去的几个小时里,我一直在追逐自己的尾巴,试图安装依赖项,删除 node_module 文件夹,并执行 npm cache clean。

如果你能伸出援助之手,请多多关照

编辑:使用 NPM 3.10.2 和节点 6.2.2

EDIT2:在另一台机器上尝试了上述步骤,并且成功了。将更新第一台机器的调试结果。

EDIT3:删除了所有全局 npm 包,什么都没有。代码如下:

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  }
}

typings.json

{
  "globalDependencies": {
    "core-js": "registry:dt/core-js#0.0.0+20160602141332",
    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
    "node": "registry:dt/node#6.0.0+20160621231320"
  }
}

package.json

{
  "name": "angular2-quickstart",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
  },
  "license": "ISC",
  "dependencies": {
    "@angular/common":  "2.0.0-rc.3",
    "@angular/core": "2.0.0-rc.2",
    "@angular/compiler":  "2.0.0-rc.3",
    "@angular/core":  "2.0.0-rc.3",
    "@angular/http":  "2.0.0-rc.2",
    "@angular/forms": "0.1.1",
    "reflect-metadata": "0.1.2",
    "@angular/http":  "2.0.0-rc.3",
    "@angular/platform-browser":  "2.0.0-rc.3",
    "@angular/platform-browser-dynamic":  "2.0.0-rc.3",
    "@angular/router":  "3.0.0-alpha.7",
    "@angular/router-deprecated":  "2.0.0-rc.2",
    "@angular/upgrade":  "2.0.0-rc.3",
    "systemjs": "0.19.27",
    "core-js": "^2.4.0",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.6",
    "zone.js": "^0.6.12",
    "angular2-in-memory-web-api": "0.0.12",
    "bootstrap": "^3.3.6"
  },
  "devDependencies": {
    "concurrently": "^2.0.0",
    "lite-server": "^2.2.0",
    "typescript": "^1.8.10",
    "typings":"^1.0.4"
  }
}

systemjs.config.js

/**
 * System configuration for Angular 2 samples
 * Adjust as necessary for your application needs.
 */
(function(global) {
  // map tells the System loader where to look for things
  var map = {
    'app':                        'app', // 'dist',
    '@angular':                   'node_modules/@angular',
    'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
    'rxjs':                       'node_modules/rxjs'
  };
  // packages tells the System loader how to load when no filename and/or no extension
  var packages = {
    'app':                        { main: 'main.js',  defaultExtension: 'js' },
    'rxjs':                       { defaultExtension: 'js' },
    'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
  };
  var ngPackageNames = [
    'common',
    'compiler',
    'core',
    'forms',
    'http',
    'platform-browser',
    'platform-browser-dynamic',
    'router',
    'router-deprecated',
    'upgrade',
  ];
  // Individual files (~300 requests):
  function packIndex(pkgName) {
    packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
  }
  // Bundled (~40 requests):
  function packUmd(pkgName) {
    packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
  }
  // Most environments should use UMD; some (Karma) need the individual index files
  var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
  // Add package entries for angular packages
  ngPackageNames.forEach(setPackageConfig);
  var config = {
    map: map,
    packages: packages
  };
  System.config(config);
})(this);

index.html

<html>
  <head>
    <title>Angular 2 QuickStart</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles.css">
    <!-- 1. Load libraries -->
     <!-- Polyfill(s) for older browsers -->
    <script src="node_modules/core-js/client/shim.min.js"></script>
    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/reflect-metadata/Reflect.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <!-- 2. Configure SystemJS -->
    <script src="systemjs.config.js"></script>
    <script>
      System.import('app').catch(function(err){ console.error(err); });
    </script>
  </head>
  <!-- 3. Display the application -->
  <body>
    <my-app>Loading...</my-app>
  </body>
</html>

结构

【问题讨论】:

  • 浏览器控制台有错误吗?
  • @RidaBENHAMMANE Failed to load resource: the server responded with a status of 500 (Internal Server Error)
  • 用 es6 更改 tsconfig.json 并重新运行 "compilerOptions": { "target": "es6",
  • @pro.mean 它抛出了很多类似的错误:node_modules/typescript/lib/lib.es6.d.ts(17,14): error TS2300: Duplicate identifier 'PropertyKey' ... 这发生在两个 es6-shim 都安装和没有安装的时候。如果这很重要
  • 你会在这里显示tsconfig.jsontypings.json文件的代码

标签: angularjs node.js angular


【解决方案1】:

检查您手动创建的文件的文件名,我在这里犯了同样的错误

【讨论】:

  • 不幸的是,事实并非如此。这最初是在我尝试使用这个 github repo 时开始的,厌倦了它,并尝试以手动方式进行操作。
  • @JackRothrock 我使用angular.io/docs/ts/latest/tutorial 此处提供的教程尝试了文件夹结构。尝试创建相同的,它对做什么和不做什么有明确的解释。
  • 是的,我让它在另一台机器上工作,按照我上面所做的相同的事情,并且与另一个 repo 有问题,它让我相信这是这台机器上的东西 - 什么还没有
【解决方案2】:

好的,对于其他遇到此问题的人,我遇到的问题是端口上有一个死进程。对于那些使用 Mac 的人。看看这篇文章:

Find (and kill) process locking port 3000 on Mac

【讨论】:

    猜你喜欢
    • 2017-02-07
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    • 2016-07-01
    • 1970-01-01
    • 2017-06-07
    • 2019-10-10
    • 1970-01-01
    相关资源
    最近更新 更多