首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用角CLI 12创建角元件库?

如何使用角CLI 12创建角元件库?
EN

Stack Overflow用户
提问于 2021-06-18 20:38:57
回答 1查看 403关注 0票数 1

我试图使用角度CLI生成一个角度工作区。它应该包含一个图书馆。另一个应用程序应该能够导入角npm包并显示导出的默认组件。

我用过的一代..。

ng new custom-comp-lib --createApplication=false --directory="./" --skip-tests="true"

为了创建一个新的库条目,我使用了ng generate library example-feature

> npx envinfo --system --binaries --browsers --npmPackages --duplicates --npmGlobalPackages

代码语言:javascript
运行
复制
  System:
    OS: macOS 11.4
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
    Memory: 20.63 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.15.3 - ~/.nvm/versions/node/v14.15.3/bin/node
    npm: 7.16.0 - ~/.nvm/versions/node/v14.15.3/bin/npm
  Browsers:
    Chrome Canary: 93.0.4546.0
    Firefox Developer Edition: 90.0
    Safari: 14.1.1
  npmGlobalPackages:
    @angular/cli: 12.0.5
    npm: 7.16.0

在发布npm包并将其导入到另一个角应用程序后,该模块无法解析。

火狐上的

代码语言:javascript
运行
复制
Uncaught TypeError: can't access property "\u0275mod", type is undefined
    Angular 7
        getNgModuleDef
        recurse
        recurse
        registerNgModuleType
        NgModuleFactory$1
        compileNgModuleFactory__POST_R3__
        bootstrapModule
    4431 main.ts:11
    Webpack 7
        __webpack_require__
        __webpack_exec__
        <anonymous>
        O
        <anonymous>
        webpackJsonpCallback
        <anonymous>
core.js:1117
    Angular 7
        getNgModuleDef
        recurse
        recurse
        registerNgModuleType
        NgModuleFactory$1
        compileNgModuleFactory__POST_R3__
        bootstrapModule
    4431 main.ts:11
    Webpack 8
        __webpack_require__
        __webpack_exec__
        <anonym>
        O
        <anonym>
        webpackJsonpCallback
        webpackJsonpCallback
        <anonym>

代码语言:javascript
运行
复制
ERROR TypeError: can't access property "\u0275cmp", e is undefined
    Le http://localhost:4200/main.js:1
    je http://localhost:4200/main.js:1
    directiveDefs http://localhost:4200/main.js:1
    mr http://localhost:4200/main.js:1
    gr http://localhost:4200/main.js:1
    e http://localhost:4200/main.js:1
    create http://localhost:4200/main.js:1
    bootstrap http://localhost:4200/main.js:1
    _moduleDoBootstrap http://localhost:4200/main.js:1
    _moduleDoBootstrap http://localhost:4200/main.js:1
    bootstrapModuleFactory http://localhost:4200/main.js:1
    invoke http://localhost:4200/polyfills.js:1
    onInvoke http://localhost:4200/main.js:1
    invoke http://localhost:4200/polyfills.js:1
    run http://localhost:4200/polyfills.js:1
    P http://localhost:4200/polyfills.js:1
    invokeTask http://localhost:4200/polyfills.js:1
    onInvokeTask http://localhost:4200/main.js:1
    invokeTask http://localhost:4200/polyfills.js:1
    runTask http://localhost:4200/polyfills.js:1
    _ http://localhost:4200/polyfills.js:1
main.js:1:180898
    Sn http://localhost:4200/main.js:1
    handleError http://localhost:4200/main.js:1
    bootstrapModuleFactory http://localhost:4200/main.js:1
    invoke http://localhost:4200/polyfills.js:1
    run http://localhost:4200/polyfills.js:1
    runOutsideAngular http://localhost:4200/main.js:1
    bootstrapModuleFactory http://localhost:4200/main.js:1
    invoke http://localhost:4200/polyfills.js:1
    onInvoke http://localhost:4200/main.js:1
    invoke http://localhost:4200/polyfills.js:1
    run http://localhost:4200/polyfills.js:1
    P http://localhost:4200/polyfills.js:1
    invokeTask http://localhost:4200/polyfills.js:1
    onInvokeTask http://localhost:4200/main.js:1
    invokeTask http://localhost:4200/polyfills.js:1
    runTask http://localhost:4200/polyfills.js:1
    _ http://localhost:4200/polyfills.js:1

On Chrome:

代码语言:javascript
运行
复制
ERROR TypeError: Cannot read property 'ɵcmp' of undefined
    at Le (main.js:1)
    at je (main.js:1)
    at Array.map (<anonymous>)
    at n.directiveDefs (main.js:1)
    at mr (main.js:1)
    at gr (main.js:1)
    at main.js:1
    at Qo.create (main.js:1)
    at e.bootstrap (main.js:1)
    at main.js:1

测试应用程序也只是一个默认生成的角应用程序(latest = ^12.0.5)。

代码语言:javascript
运行
复制
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ExampleFeatureModule } from 'example-feature/src/public-api';

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

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    ExampleFeatureModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }


 <h1>Hi</h1>
 <lib-example-feature></lib-example-feature>

知道为什么会失败吗?也可以在没有错误的情况下运行构建。

今天有没有人生成一个新的角库?也有类似的问题?

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-18 23:01:15

我的npm publish似乎没有使用dist资源文件夹:/

现在一切都正常了,有残疾的常春藤。

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

https://stackoverflow.com/questions/68041197

复制
相关文章

相似问题

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