Angular2-quickstart没有加载,没有错误

时间:2016-06-28 04:32:34

标签: angularjs node.js angular

我跟着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>

结构

structure

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

Find (and kill) process locking port 3000 on Mac