首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AOT角模块

AOT角模块
EN

Stack Overflow用户
提问于 2017-07-17 23:30:32
回答 1查看 242关注 0票数 0

我已经尝试导出一个简单的Angular4模块,以便在另一个项目中工作至少一个月。读了很多文章,但不起作用。在这里包含两个文件夹的文件

代码语言:javascript
复制
lib -> Containing a simple Angular4 module
demo -> Containing a simple AngularCli project

lib是角模块的一个非常简单的实现,demo在根模块中导入该模块。

无论我做什么,演示应用程序都会给我带来不同类型的错误,说明lib不是一个角度模块。有时谈论不包括装潢师,有时则是这个错误:

错误中遇到静态解析符号值的错误。不支持函数调用。考虑将函数或lambda替换为导出函数的引用(原始.ts文件中的位置194:50 ),解析符号NgModule。

我试图把目标对准es5es2015,但没有任何运气。

复制这一问题的步骤:

  1. 下载zip并将其解压缩到一个文件夹中。
  2. cd lib文件夹
  3. 运行npm installyarn install来安装依赖项
  4. 运行npm run bundleyarn bundle将库捆绑到dist
  5. cd demo文件夹
  6. 运行npm installyarn install
  7. 运行npm install ../libyarn add file:../lib安装位于lib文件夹中的本地ng-test-lib
  8. 运行npm startyarn start启动演示项目

更新:

我在这里添加一些文件的内容:

lib/src/a-module.ts

代码语言:javascript
复制
import { NgModule } from '@angular/core';
import { ADirective } from './a-directive';

@NgModule({
    declarations: [
        ADirective,
    ],
    exports: [
        ADirective,
    ]
})
export class AModule {}

lib/src/a-directive.ts

代码语言:javascript
复制
import {
    Input,
    OnInit,
    Directive,
 } from '@angular/core';

@Directive({
    selector: '[aDir]',
})
export class ADirective implements OnInit {
    @Input() test: string;

    ngOnInit() {
        console.log(`I'm the directive, and this is test value: ${this.test}`);
    }
}

lib/tsconfig.aot.json

代码语言:javascript
复制
{
    "compilerOptions": {
        "sourceMap": true,
        "inlineSources": true,
        "declaration": true,
        "noImplicitAny": false,
        "skipLibCheck": true,
        "stripInternal": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "suppressImplicitAnyIndexErrors": true,
        "module": "es2015",
        "target": "es5",
        "moduleResolution": "node",
        "lib": [
            "es2015",
            "dom"
        ],
        "outDir": "./dist",
        "rootDir": "./src",
        "baseUrl": ".",
        "types": []
    },
    "files": [
        "./src/a-module.ts"
    ],
    "angularCompilerOptions": {
        "strictMetadataEmit": true,
        "skipTemplateCodegen": true,
        "annotateForClosureCompiler": true,
        "flatModuleOutFile": "index.js",
        "flatModuleId": "index",
        "genDir": "./dist"
    }
}

有人知道这是怎么回事吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-18 00:40:37

因此,原来问题是对文件夹进行符号链接,这意味着如果使用npm install ../lib,问题就不会发生!我没有试过,因为我以为它和yarn add file:../lib一样,但没有。

最后,这是一个与@angular/compiler相关的问题,它不能正常地处理符号链接目录。

就这样。

我希望这能帮助别人不要像我那样浪费时间。

更新请注意,如果您使用npm v5,则会发生此问题,因为它使用符号链接链接本地包。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45155161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档