我试图使用角度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
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
包并将其导入到另一个角应用程序后,该模块无法解析。
火狐上的:
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>
或
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:
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
)。
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>
知道为什么会失败吗?也可以在没有错误的情况下运行构建。
今天有没有人生成一个新的角库?也有类似的问题?
提前谢谢。
发布于 2021-06-18 23:01:15
我的npm publish
似乎没有使用dist
资源文件夹:/
现在一切都正常了,有残疾的常春藤。
https://stackoverflow.com/questions/68041197
复制相似问题