하위 디렉토리의 Angular2.0, SystemJS는 각도 구성 요소를 가져올 수 없습니다. (Angular2.0 in subdirectory, SystemJS cant import angular components)


문제 설명

하위 디렉토리의 Angular2.0, SystemJS는 각도 구성 요소를 가져올 수 없습니다. (Angular2.0 in subdirectory, SystemJS cant import angular components)

Angular2.0을 시작하고 있습니다. 저는 5분 빠른 시작을 따르고 있으며 Typescript와 일부 Sass 등을 컴파일하기 위해 grunt를 사용하고 있지만 모든 것이 잘 작동합니다.

혼자 해결할 수 없는 한 가지 문제가 있습니다. . 모든 공개 파일(생성된 Javascript 및 프로덕션 노드 모듈을 하위 디렉토리로 이동하고 싶습니다. 동일한 도메인에서 다른 애플리케이션을 실행하기 때문에 해당 파일이 있어야 합니다. 프론트엔드는 로그인한 사용자 유형에 따라 다릅니다. (백엔드는 작성됨) phalcon 사용)

내 공용 폴더입니다.(웹 서버의 루트)






<hr>




<h2>참조 솔루션</h2>

<h4>방법 1:</h4> <p>Had this exact same problem, and just figured it out after several hours. The System config baseURL needs to be set BEFORE angular2.dev.js is loaded. This is because the System.register calls need to be aware of the baseURL at the time of registrations.</p><p>e.g.</p><p>System.config({ baseURL: '/talent' });</p><p>A cleaner way is to just add System.config({ baseURL: '/talent' }) to the very bottom of the system.src.js file.</p><p><h4>방법 2:</h4> <p>You can set paths for each library :</p></p>
<pre><code>System.paths = {
    'angular2/*': '/talent/node_modules/angular2/*',
    'app/*': '/talent/app/*'
};
</code></pre><p>Does this work for you?</p><p><h4>방법 3:</h4> <p><code>'angular2/angular2'</code> has been deprecated. Your code should reference <code>'angular2/core'</code> or the appropriate module for your imports.</p></p>
<p>You should also not need to specify the path for the angular2 imports in your <code>System.config</code> as System will load them in from the <code><script></code> tag you have in the HTML.</p><p>You are most likely receiving the 404 error because the <code>angular2.dev.js</code> file is loading <code>'angular2/core'</code>, <code>'angular2/common'</code>, <code>'angular2/platform/browser'</code>, etc... and you are referencing <code>'angular2/angular2'</code> which is not being registered and therefor SystemJS is attempting to go out and find it.</p><p>Change all of your <code>import {...} from 'angular2/angular2'</code> to the correct module import as well. You can find these on the API Preview page of angular.io, or hopefully your IDE will find it for you.</p><p><h4>방법 4:</h4> <p>I don't know which version of Angular2 you use but now with beta versions you should use these Angular2 modules:</p></p>
<pre><code>import {bootstrap} from 'angular2/platform/browser';
import {Component} from 'angular2/core';
</code></pre><p>Then you need to configure SystemJS as described below:</p><pre><code><script>
  System.config({
    map: {
      app: 'talent/app'
    },
    packages: {        
      app: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
  System.import('app/boot')
        .then(null, console.error.bind(console));
</script>
</code></pre><p>With this configuration, when trying to load the <code>app/boot</code> module, SystemJS will load the <code>talent/app/boot.js</code> file that was compiled before from the <code>talent/app/boot.ts</code> file. This behavior applies to all elements under the <code>app</code> module but not to other ones.</p><p>Modules like <code>angular2/*</code> will be found from files <code>talent/node_modules/angular2/bundles/[something].js</code> you included using <code><script></code> tags.</p><p>I made some tests and this configuration works for me ;‑)</p><p>Thierry</p><p><h4>방법 5:</h4> <p>I stumbled upon this question when trying to move from a local (dev) environment to a hosted server (CentOS) where the deployed URLs were all different to my local host.  If you're in this situation and the accepted answer doesn't solve your problem (I was already importing the updated imports with Angular2 Beta 15) and using baseURL messes other things up (as it did in my situation) then use:</p></p>
<pre><code>map: {
    app: 'path/to/app/folder'
},
</code></pre><p>I saw this here and it worked for me (even though it was originally answering a MAMP environment question): <a href=Troubles with importing classes from Angular 2 modules with Typescript 1.7

(by DafenrunmarketsCamille WintzSnareChopsThierry Templieruser2499264)

참조 문서

  1. Angular2.0 in subdirectory, SystemJS cant import angular components (CC BY‑SA 2.5/3.0/4.0)

#gruntjs #web-deployment #TypeScript #systemjs #angular






관련 질문

프로그램에서 연속적으로 오류 코드를 받는 Gruntfile (Gruntfile getting error codes from programs serially)

grunt.initConfig() 전에 비동기 작업을 수행하려면 어떻게 해야 합니까? (How can I perform an asynchronous operation before grunt.initConfig()?)

grunt 및 qunit을 사용한 로깅 (Logging with grunt and qunit)

Intellij IDEA 13 - 최신 JS 파일을 사용한 아티팩트 빌드 프로세스(grunt 빌드를 통해) (Intellij IDEA 13 - Artifact build process with latest JS files (Via grunt build))

IntelliJ IDEA에서 Grunt 작업에 대한 사용자 지정 config.json 위치 설정 (Setup custom config.json location for Grunt tasks in IntelliJ IDEA)

Grunt 및 Compass와 함께 node-normalize-scss 사용 (Using node-normalize-scss with Grunt and Compass)

npm grunt-libsass 설치 오류 (Error installing npm grunt-libsass)

루트 폴더에 없는 Gruntfile.js가 있는 Visual Studio 작업 실행기 탐색기 (Visual Studio Task Runner Explorer with Gruntfile.js that is not in the root folder)

하위 디렉토리의 Angular2.0, SystemJS는 각도 구성 요소를 가져올 수 없습니다. (Angular2.0 in subdirectory, SystemJS cant import angular components)

html5 모드를 사용하여 Angular 다시 로드 (Reload Angular using html5 mode)

그런트 작업 옵션을 이해하는 방법 (How to understand Grunt task options)

오류: 프로젝트의 기본 XML 네임스페이스는 MSBuild XML 네임스페이스여야 합니다. (Error: The default XML namespace of the project must be the MSBuild XML namespace)







코멘트