无法加载@ angular / platform-b​​rowser-dynamic

时间:2016-07-05 21:06:00

标签: angular

当应用程序加载时,我收到以下错误。

http://localhost:49769/node_modules/@angular/platform-browser-dynamic/index.js Failed to load resource: the server responded with a status of 404 (Not Found)
localhost/:21 Error: Error: XHR error (404 Not Found) loading http://localhost:49769/node_modules/@angular/platform-browser-dynamic/index.js
        at XMLHttpRequest.wrapFn [as _onreadystatechange] (https://npmcdn.com/zone.js@0.6.12?main=browser:769:30)
        at ZoneDelegate.invokeTask (https://npmcdn.com/zone.js@0.6.12?main=browser:356:38)
        at Zone.runTask (https://npmcdn.com/zone.js@0.6.12?main=browser:256:48)
        at XMLHttpRequest.ZoneTask.invoke (https://npmcdn.com/zone.js@0.6.12?main=browser:423:34)
    Error loading http://localhost:49769/node_modules/@angular/platform-browser-dynamic/index.js as "@angular/platform-browser-dynamic" from http://localhost:49769/app/main.js(anonymous function) @ localhost/:21
http://localhost:49769/node_modules/@angular/core/index.js Failed to load resource: the server responded with a status of 404 (Not Found)

请找到在我的项目中放置config和.ts文件的文件夹结构。请验证文件是否放在正确的文件夹enter image description here

的package.json

{
  "name": "Testing",
  "version": "1.0.0",
  "scripts": {
    "start": "concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lint": "tslint ./app/**/*.ts -t verbose",
    "lite": "lite-server",
    "typings": "typings",
    "postinstall": "typings install"
  },
  "license": "ISC",
  "dependencies": {
    "@angular/common": "2.0.0-rc.4",
    "@angular/compiler": "2.0.0-rc.4",
    "@angular/core": "2.0.0-rc.4",
    "@angular/forms": "0.2.0",
    "@angular/http": "2.0.0-rc.4",
    "@angular/platform-browser": "2.0.0-rc.4",
    "@angular/platform-browser-dynamic": "2.0.0-rc.4",
    "@angular/router": "3.0.0-beta.2",

    "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",

    "bootstrap": "^3.3.6"
  },
  "devDependencies": {
    "concurrently": "^2.0.0",
    "lite-server": "^2.2.0",
    "tslint": "^3.7.4",
    "typescript": "^1.8.10",
    "typings": "^1.0.4"
  },
  "repository": { }
}

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',
        'rxjs': 'node_modules/rxjs',
        '@angular': 'node_modules/@angular'

    };

    // 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' },

        '@angular/common': { defaultExtension: 'js', main: 'index.js' },
        '@angular/compiler': { defaultExtension: 'js', main: 'index.js' },
        '@angular/core': { defaultExtension: 'js', main: 'index.js' },
        '@angular/http': { defaultExtension: 'js', main: 'index.js' },
        '@angular/platform-browser': { defaultExtension: 'js', main: 'index.js' },
        '@angular/platform-browser-dynamic': { defaultExtension: 'js', main: 'index.js' },
        '@angular/router': { defaultExtension: 'js', main: 'index.js' },

    };

    var packageNames = [
      '@angular/common',
      '@angular/compiler',
      '@angular/core',
      '@angular/forms',
      '@angular/http',
      '@angular/platform-browser',
      '@angular/platform-browser-dynamic',
      '@angular/router'
    ];

    // add package entries for angular packages in the form 
    // '@angular/common': { main: 'index.js', defaultExtension: 'js' }
    packageNames.forEach(function (pkgName) {
        packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
    });

    var config = {
        map: map,
        packages: packages
    };

    System.config(config);

})(this);

tsconfig.json

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

为什么应用程序无法在node_modules下加载platform-b​​rowser-dynamic?我验证了文件存在于指定的文件夹下,但我仍然收到此错误。

注意:虽然NPM / Dependencies文件夹中说“未安装”,但我可以展开文件夹并注意所有引用都已正确安装,但仍显示此错误/警告消息

1 个答案:

答案 0 :(得分:3)

您无法从node_modules导入wwwroot,但您必须在wwwroot中的目标文件夹中复制捆绑包,例如gulp,然后从那里导入它们systemjs.config.js。 wwwroot中的systemjs.config.js位置是正确的。

我建议您按照以下几个示例进行操作:https://github.com/ajtowf/aspnetcore-angular2-seed