当前位置:  开发笔记 > 前端 > 正文

EXCEPTION:必须定义令牌!angular2

如何解决《EXCEPTION:必须定义令牌!angular2》经验,为你挑选了1个好方法。

我正在处理我的第一个ES6应用程序,angular2并且在使用es7装饰器语法时无法使其工作.

entry.js

import * as stylesheet from '../assets/styles/app.scss';

import $ from 'jquery';
import jQuery from 'jquery';
// export for others scripts to use
window.$ = $;
window.jQuery = jQuery;

import './boot'
import {AppComponent} from './app.component'

boot.js

(function (app) {
    document.addEventListener('DOMContentLoaded', function () {
        ng.platform.browser.bootstrap(app.AppComponent);
    });
})(window.app || (window.app = {}));

app.component.js

import {Component} from 'angular2/core';

@Component({
    selector: 'my-app',
    template: '

My First Angular 2 App

' }) export class AppComponent { constructor() { } }

的package.json

{
  "main": "index.js",
  "scripts": {
    "build": "npm-run-all clean prepare build:style build:app",
    "build:app": "browserify -e ./app/index.js -o ./dist/app.js",
    "build:production": "npm prune && npm install && npm run lint && npm test && npm run build",
    "build:style": "npm run build:semantic-ui; npm run copy:style",
    "build:semantic-ui": "gulp --gulpfile ./node_modules/semantic-ui/gulpfile.js build",
    "copy:style": "cp -r semantic/dist/* ./dist/styles",
    "clean": "rimraf ./dist/**/*",
    "lint": "jshint app/**",
    "prepare": "mkdir -p ./dist",
    "prestart": "npm run build",
    "pretest": "npm install",
    "screenshot": "node tests/screenshot.js",
    "serve": "static -p ${PORT:-5000} --gzip --host-address 0.0.0.0 ./",
    "start": "npm run serve",
    "test": "mocha --compilers js:babel-core/register tests",
    "watch": "PORT=${PORT:-5000} npm-run-all --parallel serve watch:app",
    "watch:app": "watchify -dv -e ./app/index.js -o ./dist/app.js",
    "watch:tests": "npm test -- -w"
  },
  "devDependencies": {
    "browserify": "latest",
    "babel-core": "6.3.x",
    "babel-eslint": "^5.0.0-beta6",
    "babel-plugin-angular2-annotations": "3.0.x",
    "babel-plugin-transform-class-properties": "6.3.x",
    "babel-plugin-transform-decorators-legacy": "1.3.x",
    "babel-plugin-transform-flow-strip-types": "6.3.x",
    "babel-preset-es2015": "6.3.x",
    "babelify": "7.2.x",
    "babylon": "6.3.x",
    "csscritic": "https://github.com/cburgmer/csscritic.git",
    "jshint": "2.8.x",
    "mocha": "^2.3.4",
    "node-static": "0.7.x",
    "npm-run-all": "1.4.x",
    "pageres": "3.0.x",
    "rimraf": "2.4.x",
    "sassify": "0.9.x",
    "semantic-ui": "2.1.x",
    "watchify": "3.6.x"
  },
  "dependencies": {
    "jquery": "latest",
    "babel-polyfill": "^6.3.14",
    "angular2": "^2.0.0-beta.0",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.13",
    "reflect-metadata": "^0.1.2",
    "rxjs": "^5.0.0-beta.0",
    "zone.js": "^0.5.10"
  },
  "babel": {
    "presets": [
      "es2015"
    ],
"plugins": [
    "angular2-annotations",
    "transform-decorators-legacy",
    "transform-class-properties",
    "transform-flow-strip-types"
  ]
  },
  "browserify": {
    "transform": [
      [
        "babelify",
        {
          "presets": [
            "es2015"
          ]
        }
      ],
      [
        "sassify",
        {
          "auto-inject": true
        }
      ]
    ]
  },
  "jshintConfig": {
    "esnext": true
  }
}

的console.log

EXCEPTION: Token must be defined! angular2-all.umd.js:29460
EXCEPTION: Token must be defined! angular2-all.umd.js:29451:14

STACKTRACE: angular2-all.umd.js:29451:14

BaseException@http://localhost:5000/node_modules/angular2/bundles/angular2-all.umd.js:4350:24
Key@http://localhost:5000/node_modules/angular2/bundles/angular2-all.umd.js:4924:20
KeyRegistry

这是怎么回事?我该如何解决这个问题?

有关

将Angular2组件转换为ES6语法需要什么?

如何在没有装饰器语法的情况下编写angular2?

Blacksonic.. 5

在我的情况下,这是因为我给的课程bootstrapundefined.

如果您的目标是制作Angular 2应用程序的骨架ES6版本,我创建了一个工作示例,其中所有内容都设置为工作并接受装饰器.



1> Blacksonic..:

在我的情况下,这是因为我给的课程bootstrapundefined.

如果您的目标是制作Angular 2应用程序的骨架ES6版本,我创建了一个工作示例,其中所有内容都设置为工作并接受装饰器.

推荐阅读
TXCWB_523
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有